Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104168 > unrolled thread

Re: reversed(zip(...)) not working as intended

Started byMRAB <python@mrabarnett.plus.com>
First post2016-03-06 19:00 +0000
Last post2016-03-06 19:00 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: reversed(zip(...)) not working as intended MRAB <python@mrabarnett.plus.com> - 2016-03-06 19:00 +0000

#104168 — Re: reversed(zip(...)) not working as intended

FromMRAB <python@mrabarnett.plus.com>
Date2016-03-06 19:00 +0000
SubjectRe: reversed(zip(...)) not working as intended
Message-ID<mailman.266.1457291042.20602.python-list@python.org>
On 2016-03-06 18:29, Sven R. Kunze wrote:
> Hi,
>
> what's the reason that reversed(zip(...)) raises as a TypeError?
>
> Would allowing reversed to handle zip and related functions lead to
> strange errors?
>
'reversed' yields the items in reverse order; it needs the last item first.

Iterators yield items from the first to the last.

'reversed' would have to get and store all of the items from the 
iterator. It won't know which is the last item until the iterator raises 
StopIteration.

Only then will it be able to yield the items in reverse order.

It's much better for it to complain, and leave it for the user to do it 
explicitly with reversed(list(zip(...))).

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web