This is probably a noob question. For any dictionary ‘d’ in python is this always True:
dict( zip( d.keys(), d.values() ) ) == d
Are the keys and values returned in the same corresponding order ?
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.
Yes it’s always true. Guaranteed by Python iff there are no intervening modifications to the ditionary.
Relevant spec: http://docs.python.org/library/stdtypes.html#dict.items
This is better generally, both because it protects against the dict going out of sync and uses negligible extra memory:
dict((k,v) for k,v in d.iteritems())