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


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

Re: reversed(enumerate(x))

Started byMichael Selik <michael.selik@gmail.com>
First post2016-07-20 20:54 -0500
Last post2016-07-20 20:54 -0500
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(enumerate(x)) Michael Selik <michael.selik@gmail.com> - 2016-07-20 20:54 -0500

#111687 — Re: reversed(enumerate(x))

FromMichael Selik <michael.selik@gmail.com>
Date2016-07-20 20:54 -0500
SubjectRe: reversed(enumerate(x))
Message-ID<mailman.12.1469066103.22221.python-list@python.org>
> 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.

[toc] | [standalone]


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


csiph-web