defining the behavior of zip(it, it) (WAS: Converting a flat list...)

Steven Bethard steven.bethard at gmail.com
Tue Nov 22 17:42:06 EST 2005


[Duncan Booth]
 > >>> aList = ['a', 1, 'b', 2, 'c', 3]
 > >>> it = iter(aList)
 > >>> zip(it, it)
 >[('a', 1), ('b', 2), ('c', 3)]

[Alan Isaac]
 > That behavior is currently an accident.
 >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416

[Bengt Richter]
 > That says
 > """
 > ii. The other problem is easier to explain by example.
 > Let it=iter([1,2,3,4]).
 > What is the result of zip(*[it]*2)?
 > The current answer is: [(1,2),(3,4)],
 > but it is impossible to determine this from the docs,
 > which would allow [(1,3),(2,4)] instead (or indeed
 > other possibilities).
 > """
 > IMO left->right is useful enough to warrant making it defined
 > behaviour

And in fact, it is defined behavior for itertools.izip() [1].

I don't see why it's such a big deal to make it defined behavior for 
zip() too.

STeVe

[1]http://docs.python.org/lib/itertools-functions.html#l2h-1392



More information about the Python-list mailing list