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
Post a Comment