Saturday, 17 August 2013

python: iterating through a dictionary with list values

python: iterating through a dictionary with list values

Given a dictionary of lists, such as
d = {'1':[11,12], '2':[21,21]}
Which is more pythonic or otherwise preferable:
for k in d:
for x in d[k]:
# whatever with k, x
or
for k, dk in d.iteritems():
for x in dk:
# whatever with k, x
or is there something else to consider?

No comments:

Post a Comment