On Thu, Jan 21, 2021 at 1:26 PM Chris Angelico <[email protected]> wrote:
>
> On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar <[email protected]> wrote:
> >
> > I've seen this proposed here before.  The general idea is that some 
> > iterator transformations (like enumerate) should return sequences when 
> > they're applied to sequences.  I think it's good idea, but it adds 
> > complexity and work, which I guess needs to be justified on a case-by-case 
> > basis.
> >
> > In short, this has nothing to do with reversed.  If you made enumerate 
> > return a sequence when its input is a sequence, you would also be able to 
> > do enumerate(some_list)[34], which could also be useful.  I think it makes 
> > Python slightly more perfect and more beautiful.
> >
>
> list(enumerate(some_list)) will give you a sequence, if that's what you want.

Right.  And reversed(list(enumerate(some_list)) also works.  The point
is that if you return sequence views (as Andrew mentioned), you don't
need to cast to list explicitly, and you don't pay the computational
cost of that either.

>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/[email protected]/message/WW3JHS234TJSXKUICY4PG2SPDTD3SBUP/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the Google 
> Groups "python-ideas" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/python-ideas/3wGART2ECXQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/python-ideas/CAPTjJmpPchBQEWVP1Mt8UW3aaquTKx2kLVrxhc%3DV7LOpD%3Db7XQ%40mail.gmail.com.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/RPKLUPE4XINPWKORTJU6TGUENPQ3UVXD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to