What’s the best way to initialize (e.g. before a loop) a dictionary that will contain strings and a list in each item?
For instance:
dict = [("string1", [1,2]), ("string2", [5,6]),..]
So:
dict["string1"]
returns:
[1,2]
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.
Please don’t call a variable dict (or list, or set, etc) because it “covers up” existing functions and prevents you from using them.
If you’re a bit of a masochist, you can also try
or (per cval’s example)