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


Groups > comp.lang.python > #111687

Re: reversed(enumerate(x))

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: reversed(enumerate(x))
Date 2016-07-20 20:54 -0500
Message-ID <mailman.12.1469066103.22221.python-list@python.org> (permalink)
References <CALwzid=_6zUhLLp-WU9RcqJn0kic8q_LA9fcytG3srqGr+Q2MQ@mail.gmail.com> <B373842F-34E1-4FAC-B97A-15EDB42DCF05@gmail.com>

Show all headers | View raw


> On Jul 20, 2016, at 12:42 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> 
>    for i, n in reversed(enumerate(x)): pass
> 
> fails with "TypeError: argument to reversed() must be a sequence".

So make it a sequence:
    for i, n in reversed(list(enumerate(x))): pass

If ``x`` is very large, you can use your zip/range technique to save memory.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: reversed(enumerate(x)) Michael Selik <michael.selik@gmail.com> - 2016-07-20 20:54 -0500

csiph-web