[Inspired by this question ]
Suppose I have two lists:
list1 = ['tom', 'mary', 'frank', 'joe', 'john', 'barry']
list2 = [1, 2, 3, 4]
I want to match each name in list1with number in list2. Since list2there are four numbers in, I would like to associate each of the first four names with the corresponding number in list2and assign random numbers to the remaining names in list1.
I know that I can solve this problem using for-loop with enumerateand random.choice. Indeed, I provided such a solution to the original problem.
I would like to know, however, if you can do something like this:
for name, number in itertools.izip_longest(list1, list2, fillvalue=MAGIC):
print name, number
I originally thought of using something like this:
MAGIC = random.choice(list1)
, random.choice(list1), fillvalue zipping. , , . , itertools.izip_longest fillvalue , , . , , , , . lambda .
, ? itertools.izip_longest fillvalue? __repr__ ? , __repr__, ?