Yes, Python has dictionary comprehensions. You almost have the syntax correct. If you have two sequences, one of keys, and one of values, this will work:
myDict = {k:v for (k,v) in zip(keys, values)}
Yes, Python has dictionary comprehensions. You almost have the syntax correct. If you have two sequences, one of keys, and one of values, this will work:
myDict = {k:v for (k,v) in zip(keys, values)}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
John L.
05/24/19