Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:30+00:00 2026-05-26T22:55:30+00:00

Obviously, the title has code that can’t be interpreted. An uninformative SyntaxError: invalid syntax

  • 0

Obviously, the title has code that can’t be interpreted. An uninformative

SyntaxError: invalid syntax

stderr message didn’t tell me much, so I threw it in line by line, using:

[dict.get(['val','val','foo'])]

and have since discovered that dict.get() and iterables don’t play well together.

If you haven’t already guessed, I’m in the exciting field of building toy programs for learning and amusement. Here’s my code:

def wordpoints(word):
    points = 0
    for char in word:
        points += dict.get(char)
    return points

Here’s what I want:

def wordpoints(word):
    return sum[dict.get(char) for char in word]

For clarification, dict is named tile_p in my code, and stands for tile points. There is another def that looks up the scrabble player’s dictionary for True|False results in a MySQL table, and passes it to this function if it cursor.fectchone() has something in it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:55:31+00:00Added an answer on May 26, 2026 at 10:55 pm

    Use parentheses, not brackets, to call a function:

    def wordpoints(word):
        return sum(dict.get(char) for char in word)
    

    The parser actually told you a bit more than just “invalid syntax”:

        return sum[dict.get(char) for char in word]
                                    ^
    SyntaxError: invalid syntax
    

    See the little ^? It points to the token that cause parsing to fail. Up to this point, all is fine for the parser: It sees a name (sum) followed by the subscription operator []. Inside the brackets, it expects an arbitrary expression. Up to dict.get(char), this is a valid expression, but the following token for does not make sense to the parser — hence the syntax error at this point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Obviously the point of using named constants over magic numbers is for code clarity
Obviously it's early days, I do not know whether this is information that is
Although obviously not all scenarios can be covered by a single design, is it
I'm using c# to interact with a database that has an exposed REST API.
It has been stated that the google plus-one button works it's way up the
The title of this question isn't so clear, but the code and question is
I am working on an app that has several different views, two of the
OK, so I couldn't really think of an apropos title that summarizes this. The
Something is wrong with my code. Chrome code spectrator say that there is probmel
Here's a question for everyone, I has a list of sharepoint sites that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.