I am a python newbie and 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)
zipall = zip(x1, x2, x3)
print "len of zipall %s" % len(zipall)
zip() together three lists containing 20 elements each, the result has twenty elements. Each element is a three-tuple.
See for yourself:
In : a = b = c = range(20) In : zip(a, b, c) Out: [(0, 0, 0), (1, 1, 1), ... (17, 17, 17), (18, 18, 18), (19, 19, 19)]
To find out how many elements each tuple contains, you could examine the length of the first element:
In : result = zip(a, b, c) In : len(result) Out: 3
Of course, this won't work if the lists were empty to start with.