I have a Python code similar to this one:
for lines in zip(*files):
# do something
where files is a list of files, each file is a list of lines and each line is a list of strings. Therefore, the code above should first unpack the list files and then apply the function zip(), returning a tuple with the first line of each file. The problem is that this works just fine, if the length of the list of files is 30 (for example). However, if the lenght is bigger, for instance, 120, the code inside the loop doesn’t get executed even once.
The conclusion is that either the zip() function is returning an empty list or the * operator is not doing its job. Either way, my question is if there is a limit in the arguments that zip() can handle (or * can unpack) or it is somehow limited by the amount of memory that my computer has, since I haven’t been able to find anything in Python’s documentation.
PS: I’m running Python 2.4
If one of the files is empty,
zipwill return an empty list. As of Python 2.6 you can useitertools.izip_longestto handle that. On older versions, you can usemap(None, *files), courtesy of @Sven Marnach.