[Tutor] Creating a list from other lists

Saad Javed sbjaved at gmail.com
Mon Oct 22 12:21:41 CEST 2012


Hi,

I'm trying to create a list (L) from items of different lists (a, b, c) but
in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
L = []
a = [1, 2, 3, 4]
b = ['a', 'b', 'c', 'd']
c = [2009, 2010, 2011, 2012]

for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L

But this outputs:
[[1, 'a', 2009]]
[[1, 'a', 2009], [2, 'b', 2010]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd', 2012]]

I just want L = [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd',
2012]]

Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121022/414b62a6/attachment.html>


More information about the Tutor mailing list