python - Can you use enumerate for multiple objects? -
i'm wondering if have 2 (or maybe more) dictionaries defined in python keys , corresponding data, can access both elements enumerate statement?:
for i, key1, key2 in enumerate(dict1,dict2) ... "do something" thanks!
no, can this:
for i, (key1, key2) in enumerate(zip(dict1, dict2)): # pass but remember:
- a dictionary's elements unordered, can't predict in order keys appear - might change when dictionaries grow.
- if 1 dictionary has more elements other, of keys won't show in iteration. if both dictionaries have same size it'll work fine.
Comments
Post a Comment