Extended zip() for lists

Fredrik Lundh fredrik at pythonware.com
Thu Jun 8 15:23:00 CEST 2006


Florian Reiser wrote:

> I have 4 lists: a, b, c and d
> Out of this 4 lists I want to build a table (e.g. list of lists):
> 
> a|b|c|d
> ---------------------------
> a1|b1|c1|d1
> a1|b2|    |d2
> 
> You see: the lists are not equally sized.
> Is there a command which fills up the shorter lists with blanks?
> Like an enhanced zip() command, maybe?

like map(None, ...), perhaps ?

 >>> a = "1234"
 >>> b = "12"
 >>> c = "123"
 >>> d = "1234"
 >>> zip(a, b, c, d)
[('1', '1', '1', '1'), ('2', '2', '2', '2')]
 >>> map(None, a, b, c, d)
[('1', '1', '1', '1'), ('2', '2', '2', '2'), ('3', None, '3', '3'), 
('4', None, None, '4')]

</F>




More information about the Python-list mailing list