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

Steven Bethard steven.bethard at gmail.com
Wed Nov 23 01:17:31 EST 2005


rhettinger at gmail.com wrote:
>> > 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.
> 
> 
> IIRC, this was discussednd rejected in an SF bug report.  It should not
> be a defined behavior for severals reasons:
[snip arguments about how confusing zip(it, it) is]
> Overall, I think anyone using zip(it,it) is living in a state of sin,
> drawn to the tempations of one-liners and premature optimization.  They
> are forsaking obvious code in favor of screwy special cases.  The
> behavior has been left undefined for a reason.

Then why document itertools.izip() as it is?  The documentation there is 
explicit enough to know that izip(it, it) will work as intended.  Should 
we make the documentation there less explicit to discourage people from 
using the izip(it, it) idiom?

STeVe



More information about the Python-list mailing list