I have two lists:
frame = [\"mercury\", \"noir\", \"silver\", \"white\" ]
seat_colors = [
\"coconut white\", \"yello\", \"black\", \"green\",
Use itertools.izip_longest() to keep zipping until the longest sequence has been exhausted.
This uses a default value (defaulting to None
) to stand in for the missing values of the shorter list.
However, your output is creating the product of two lists; use itertools.product() for that:
from itertools import product
for a_frame, color in product(frame, seat_colors):
print '{}, {}'.format(a_frame, color)
The two concepts are quite different. The izip_longest()
approach will produce len(seat_colors)
items, while the product produces len(seat_colors) * len(frame)
items instead.
You can use itertools.product:
import itertools
for item in itertools.product(frame, seat_colors):
print item
This produces the same results as your nested for loops.