Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104168
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: reversed(zip(...)) not working as intended |
| Date | 2016-03-06 19:00 +0000 |
| Message-ID | <mailman.266.1457291042.20602.python-list@python.org> (permalink) |
| References | <56DC7727.1090001@mail.de> |
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(...))).
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: reversed(zip(...)) not working as intended MRAB <python@mrabarnett.plus.com> - 2016-03-06 19:00 +0000
csiph-web