I am trying to do something like this:
_dict = {"foo" : 1234,
"bar" : _dict["foo"] + 1}
Cant seem to get the syntax correct, is there a way to acomplish this without using multiple dictionaries, or defining them elsewhere?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You cannot access
_dictwhile defining it. Python first evaluates the{...}dict literal before assigning it to_dict. In other words, while evaluating the{...}dict literal statement,_dictis not yet defined and thus cannot be accessed.Do this instead: