Rectangle 27 0

list Python: zip like function that pads to longest length?


>>> list(map(None, a, b, c)) Traceback (most recent call last):   File "<pyshell#10>", line 1, in <module>     list(map(None, a, b, c)) TypeError: 'NoneType' object is not callable
>>> map(None, a, b, c)
[('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]

Do we not have a non itertools Python 3 solution?

You can either use itertools.izip_longest (Python 2.6+), or you can use map with None. It is a little known feature of map (but map changed in Python 3.x, so this only works in Python 2.x).

Note
Rectangle 27 0

list Python: zip like function that pads to longest length?


>>> list(map(None, a, b, c)) Traceback (most recent call last):   File "<pyshell#10>", line 1, in <module>     list(map(None, a, b, c)) TypeError: 'NoneType' object is not callable
>>> map(None, a, b, c)
[('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]

@PascalvKooten it is not required. itertools is a builtin C module anyway.

Do we not have a non itertools Python 3 solution?

You can either use itertools.izip_longest (Python 2.6+), or you can use map with None. It is a little known feature of map (but map changed in Python 3.x, so this only works in Python 2.x).

Note
Rectangle 27 0

list Python: zip like function that pads to longest length?


>>> list(map(None, a, b, c)) Traceback (most recent call last):   File "<pyshell#10>", line 1, in <module>     list(map(None, a, b, c)) TypeError: 'NoneType' object is not callable
>>> map(None, a, b, c)
[('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

@PascalvKooten it is not required. itertools is a builtin C module anyway.

Do we not have a non itertools Python 3 solution?

You can either use itertools.izip_longest (Python 2.6+), or you can use map with None. It is a little known feature of map (but map changed in Python 3.x, so this only works in Python 2.x).

Note
Rectangle 27 0

list Python: zip like function that pads to longest length?


>>> list(itertools.izip_longest(a, b, c))
[('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]
itertools
izip_longest
zip_longest

In case you want to make your code both python 2 and python 3 compatible, you can use six.moves.zip_longest instead.

Note
Rectangle 27 0

list Python: zip like function that pads to longest length?


>>> list(itertools.izip_longest(a, b, c))
[('a1', 'b1', 'c1'), (None, 'b2', 'c2'), (None, 'b3', None)]
itertools
izip_longest
zip_longest

In case you want to make your code both python 2 and python 3 compatible, you can use six.moves.zip_longest instead.

Note