I want to perform:
for i in list_a:
for j in list_b[i]:
print(i, j)
Is it possible to do it using itertools? I am looking for something like:
for i, j in itertools.product(list_a, list_b[i])
I want to do that for speed and readability.
[ call_some_function(i,j) for i in list_a for j in list_b[i] ], but that's still fundamentally a nested for-loop.stuff = (call_some_function(i, j) for i in list_a for j in list_b[i])And then you can iterate over that lazily without wasting memory materializing a list:for thing in stuff: do_some_more_stuff(thing)