python: iterate through two objects in a list at once -


have call sql db via python returns output in paired dictionaries within list:

[{'something1a':num1a}, {'something1b':num1b}, {'something2a':num2a} ...] 

i want iterate through list pull 2 dictionaries @ same time.

i know for obj1, obj2 in <list> isn't right way this, is?

you can using zip iterator on list:

>>> dicts = [{'1a': 1}, {'1b': 2}, {'2a': 3}, {'2b': 4}] >>> obj1, obj2 in zip(*[iter(dicts)]*2):     print obj1, obj2   {'1a': 1} {'1b': 2} {'2a': 3} {'2b': 4} 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -