I am trying to learn how to “zip” lists. To this end, I have a program, where at a particular point, I do the following:
x1, x2, x3 = stuff.calculations(withdataa)
This gives me three lists, x1, x2, and x3, each of, say, size 20.
Now, I do:
zipall = zip(x1, x2, x3)
However, when I do:
print "len of zipall %s" % len(zipall)
I get 20, which is not what I expected. I expected three. I think I am doing something fundamentally wrong.
When you
zip()together three lists containing 20 elements each, the result has twenty elements. Each element is a three-tuple.See for yourself:
To find out how many elements each tuple contains, you could examine the length of the first element:
Of course, this won’t work if the lists were empty to start with.