Iterate#
break
iterable
into lists of lengthn
:list(more_itertools.chunked(iterable, n))
- seeflatten a list of lists:
list(itertools.chain.from_iterable(list_of_lists))
Dict#
Iterate keys of dict#
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print(key, 'corresponds to', d[key])
Iterate keys and values of dict:#
d = {'x': 1, 'y': 2, 'z': 3}
for key, value in d.items():
print(key, 'corresponds to', value)