I have a larger list that I want to assign or otherwise take action on by elements of a smaller list, but do so only once. For example:
emailList = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
fileList = ['file_1.zip', 'file_2.zip']
I want to alternately assign the elements of fileList to the elements of emailList. So:
[email protected] -> file_1.zip
[email protected] -> file_2.zip
[email protected] -> file_1.zip
[email protected] -> file_2.zip
I have this...half working (for simplicity's sake, I'm just using print statements to represent action):
for email in emailList:
for file in zippedList:
print(email + "will receive " + file)
zippedList.pop(0)
Yields:
Email: [email protected]
will receive Contest_Packet_1.zip
Email: [email protected]
will receive Contest_Packet_2.zip
Of course the propblem is that once zippedList is empty, it ends, and no further assignments are made. However, when I do NOT pop the elements of the smaller list, then the elements of the larger list each both get both of the elements in the smaller list assigned or otherwise actioned. It yields this:
Email: [email protected]
will receive Contest_Packet_1.zip
Email: [email protected]
will receive Contest_Packet_2.zip
Email: [email protected]
will receive Contest_Packet_1.zip
Email: [email protected]
will receive Contest_Packet_2.zip
Email: [email protected]
will receive Contest_Packet_1.zip
Email: [email protected]
will receive Contest_Packet_2.zip
Email: [email protected]
will receive Contest_Packet_1.zip
Email: [email protected]
will receive Contest_Packet_2.zip
Surely there's an easier way to do this. Thoughts?