[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Random832
On Thu, Jan 21, 2021, at 19:19, Chris Angelico wrote:
> Yeah, I don't think that'll work if you slice more than once,
> especially with some iteration in between.

I think part of the point of this implementation [or the other person's 
suggestion of having a "collection view", which amounts to the same thing] is 
that iterating wouldn't consume items anymore. Which does make it incompatible 
with enumerate currently returning an iterator, though, in situations where the 
iteration is dropped and picked up again.

> The precise semantics for mixing iteration and slicing are complex
> enough and variable enough that you may as well just go for a concrete
> list at that point.

I do think it's possible to have well-defined semantics [next() could simply 
return self[0] and increment a value to be added to input indices], but it's 
probably not worth it. I'd say this and e.g. similar map/zip functions belong 
in a "sequencetools" module rather than replacing the builtin, so that 
compatibility in these situations doesn't need to be maintained.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/D67HZZ2QX22SZ427Y6UKAB44UHIKHTL3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 11:48 AM Neil Girdhar  wrote:
> If enumerate(some_sequence) returns a sequence view, iterating over
> that sequence view does not advance it—just like how DictViews are not
> altered by iteration.  Same thing if reversed(some_sequence) returns a
> sequence view.

Then that's backward incompatible with current behaviour, and cannot
be done just as "it's a sequence so return a sequence view". Hence the
suggestion of a parameter to control this - or, my preferred way: a
"seqview" module from which you can import a sequence-view-only
version of various iterator functions.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4HTQLRKKDAV7YE4JCOJPSUBIYUWIKYSI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Neil Girdhar
On Thu, Jan 21, 2021 at 7:19 PM Chris Angelico  wrote:
>
> On Fri, Jan 22, 2021 at 11:10 AM Random832  wrote:
> >
> > On Thu, Jan 21, 2021, at 18:48, Chris Angelico wrote:
> > > Note that slicing is NOT easy. The proposed semantics for a reversed
> > > enumeration would make slicing extremely odd.
> >
> > What proposed semantics? You were the one who posted a pure-python 
> > implementation that didn't bother to implement slicing.
>
> Ah, my bad. This thread started out on python-dev before migrating to
> -ideas, and I believe the proposed semantics may have been on one of
> the early -dev posts.
>
> The proposal was, effectively, to be the same as enumerating, making a
> concrete list, and then reversing (only, without actually building the
> list, of course). So enumerate("abc") yields [(0,'a'),(1,'b'),
> (2,'c')], and iterating backwards should yield those same tuples in
> reverse order.
>
> But if you take the reversed enumeration, iterate over it a bit, and
> then slice it, the semantics will be extremely bizarre.
>
> > It's easy enough to add slicing to your Enumerated class concept, though.
> >
> > class Enumerated:
> > def __init__(self, basis, indices=None):
> > self.basis = basis
> > self.indices = indices if indices is not None else range(len(basis))
> > def __getitem__(self, idx):
> > if isinstance(idx, slice):
> > return Enumerated(self.basis, indices=self.indices[idx])
> > else:
> > return (self.indices[idx], self.basis[self.indices[idx]])
> > def __len__(self):
> > return len(self.indices)
>
> Yeah, I don't think that'll work if you slice more than once,
> especially with some iteration in between.
>
> The precise semantics for mixing iteration and slicing are complex
> enough and variable enough that you may as well just go for a concrete
> list at that point.

Can you give an example of what you mean?--because I'm pretty sure
that we're not talking about the same thing at all.

If enumerate(some_sequence) returns a sequence view, iterating over
that sequence view does not advance it—just like how DictViews are not
altered by iteration.  Same thing if reversed(some_sequence) returns a
sequence view.

So, reversed(enumerate("abc"))[2] would just be (0, 'a').

You're right that there are some minor incongruities.  The only one I
can think of off-hand is bool(enumerate(some_sequence)) would be false
when the sequence is empty.

As for candidates for sequence views, I'd like to see reversed and
enumerate to start since I can remember having to cast to list many
times and it would be convenient not to have to.  From itertools, it
would be useful for thecombinatorics operators (combinations,
permutations, product, etc.) to be sequence views.  In fact, there are
convenience functions for looking them up by index in more-itertools
as this comes up a lot (at least it did for me back when I did
contests).

>
> ChrisA
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/VTSZZK3RKSKCEG7CFHYT4TZXLMP37P3I/
> 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 
> python-ideas+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/python-ideas/CAPTjJmpboVPni3FimaTh%3DNo_GBUfTmozE4kQhXBPQCrsgmkSJg%40mail.gmail.com.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YWD7JGFSUGLMFCRJKFRQYVZYTIMW25PV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 11:10 AM Random832  wrote:
>
> On Thu, Jan 21, 2021, at 18:48, Chris Angelico wrote:
> > Note that slicing is NOT easy. The proposed semantics for a reversed
> > enumeration would make slicing extremely odd.
>
> What proposed semantics? You were the one who posted a pure-python 
> implementation that didn't bother to implement slicing.

Ah, my bad. This thread started out on python-dev before migrating to
-ideas, and I believe the proposed semantics may have been on one of
the early -dev posts.

The proposal was, effectively, to be the same as enumerating, making a
concrete list, and then reversing (only, without actually building the
list, of course). So enumerate("abc") yields [(0,'a'),(1,'b'),
(2,'c')], and iterating backwards should yield those same tuples in
reverse order.

But if you take the reversed enumeration, iterate over it a bit, and
then slice it, the semantics will be extremely bizarre.

> It's easy enough to add slicing to your Enumerated class concept, though.
>
> class Enumerated:
> def __init__(self, basis, indices=None):
> self.basis = basis
> self.indices = indices if indices is not None else range(len(basis))
> def __getitem__(self, idx):
> if isinstance(idx, slice):
> return Enumerated(self.basis, indices=self.indices[idx])
> else:
> return (self.indices[idx], self.basis[self.indices[idx]])
> def __len__(self):
> return len(self.indices)

Yeah, I don't think that'll work if you slice more than once,
especially with some iteration in between.

The precise semantics for mixing iteration and slicing are complex
enough and variable enough that you may as well just go for a concrete
list at that point.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VTSZZK3RKSKCEG7CFHYT4TZXLMP37P3I/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Random832
On Thu, Jan 21, 2021, at 18:48, Chris Angelico wrote:
> Note that slicing is NOT easy. The proposed semantics for a reversed
> enumeration would make slicing extremely odd.

What proposed semantics? You were the one who posted a pure-python 
implementation that didn't bother to implement slicing.

It's easy enough to add slicing to your Enumerated class concept, though.

class Enumerated:
def __init__(self, basis, indices=None):
self.basis = basis
self.indices = indices if indices is not None else range(len(basis))
def __getitem__(self, idx):
if isinstance(idx, slice):
return Enumerated(self.basis, indices=self.indices[idx])
else:
return (self.indices[idx], self.basis[self.indices[idx]])
def __len__(self):
return len(self.indices)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZV3DG5HEM34WY2C5ETO744XBP4SAQENU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 8:31 AM Neil Girdhar  wrote:
> It's possible for reversed(enumerate(...)) to just work if enumerate
> of a sequence were to return a sequence view.  Then you would also get
> all the other sequence operations for free like enumerate(...)[23:27],
> len(enumerate(...)), etc.

That would break backward compatibility. The behaviour of enumerate()
at the moment isn't compatible with it just suddenly being a sequence.
It would have to have some way to be told "please return a sequence".
We currently have a way to say "please return an eager sequence", so
the only thing we don't easily have is "please return a lazy
sequence", and that's possible with about four lines of custom class.

Note that slicing is NOT easy. The proposed semantics for a reversed
enumeration would make slicing extremely odd.

> > As Chris A mentioned, it's quite easy to wrap list() or tuple() around it 
> > if you want that.
>
> Yes, you can alternatively wrap with list and pay the computational
> cost.  However, as was suggested by Andrew in this thread, but has
> come up many times before, the native iteration tools could return
> views.  This saves the user having to build her own custom classes
> (along with tests, etc.).  I happen to think this is simpler and more
> beautiful.

It wouldn't work. With enumerate, you could get away with returning a
view, but let's look at map. Should that return a view? If so, does
map(...)[4] cache the result or not? If it does, you're paying the
memory cost of (potentially) the full eager list, in which case you
may as well just make the list. If it doesn't, you break expectations
badly by having it call the function more than once, potentially
giving different results. Either way, it's far better to write your
own, giving you the freedom to define the semantics the way you want
to.

It's even worse with filter(). It can't possibly know which is the 5th
element without counting from the start ("hmm, that's Fire... Earth...
Water... Air... Boron. Ah! Boron!").

What about itertools.tee()? I think the whole point of that is to
hybridize laziness and caching, but if you're going to give it a
sequence, you may as well just get multiple iterators.

I'm eyeballing itertools and really not seeing any that would benefit
from magically returning sequences. Several of them specifically exist
to provide sequence-like behaviour on non-sequence iterables (eg
islice), and others don't have a direct correlation between input
index and output index (eg dropwhile) or have other discrepancies (eg
takewhile).

Rather than try to propose that ALL native iteration tools return
views, find one that would actually benefit, and propose that.
Unfortunately, I think you'll run into the same problem that it's no
longer backward compatible, so it's still going to need a spelling to
request that it behave in sequence view mode, which is probably best
written as something like "import seqview; seqview.map(...)".

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/AJMCPNPSJHY2VUKYOPMAKFB76UCT4HQ3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Neil Girdhar
On Thu, Jan 21, 2021 at 3:13 PM Christopher Barker  wrote:
>
> On Thu, Jan 21, 2021 at 10:43 AM Neil Girdhar  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'm not so sure -- I don't think I want a sequence returned. In fact, in this 
> case, just the opposite. If you wanted a sequence, you could simply do:
>
> reversed(list(enumerate(the_iterable)))
>
> Rather, you want (or I want, anyway) is for various iterators to be able to 
> do things that require a Sequence, when given a Sequence. Or, maybe not even 
> a full Sequence, but rather, some particular aspect of a sequence -- like the 
> length, or indexability.
>
> enumerate() with a reversed flag is one. Another, I'd like is islice to 
> support negative indexing for indexing from the end. There are probably many 
> others.
>
> I'd love to see these supported. For this example:
>
> enumerate(an_iterable, reversed=True)

Don't you think this is over-complicated?

It's possible for reversed(enumerate(...)) to just work if enumerate
of a sequence were to return a sequence view.  Then you would also get
all the other sequence operations for free like enumerate(...)[23:27],
len(enumerate(...)), etc.

>
> would "just work" if an_iterable had a __len__ and a __getitem__.
>
> It would raise a TypeError if passed a non-lengthed, or non-indexable 
> iterable.
>
> -CHB
>
> > > In short, this has nothing to do with reversed.
>
> I agree.
>
> >> If you made enumerate return a sequence when its input is a sequence, you 
> >> would also be able to do enumerate(some_list)[34],
>
> As Chris A mentioned, it's quite easy to wrap list() or tuple() around it if 
> you want that.

Yes, you can alternatively wrap with list and pay the computational
cost.  However, as was suggested by Andrew in this thread, but has
come up many times before, the native iteration tools could return
views.  This saves the user having to build her own custom classes
(along with tests, etc.).  I happen to think this is simpler and more
beautiful.

Best,

Neil

>
> - Chris B
>
> --
> Christopher Barker, PhD (Chris)
>
> Python Language Consulting
>   - Teaching
>   - Scientific Software Development
>   - Desktop GUI and Web Development
>   - wxPython, numpy, scipy, Cython
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/S4BNJSIRGJT3IKK7GQCHWUWK2VLDYE4P/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Christopher Barker
On Thu, Jan 21, 2021 at 10:43 AM Neil Girdhar  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'm not so sure -- I don't think I want a sequence returned. In fact, in
this case, just the opposite. If you wanted a sequence, you could simply do:

reversed(list(enumerate(the_iterable)))

Rather, you want (or I want, anyway) is for various iterators to be able to
do things that require a Sequence, when given a Sequence. Or, maybe not
even a full Sequence, but rather, some particular aspect of a sequence --
like the length, or indexability.

enumerate() with a reversed flag is one. Another, I'd like is islice to
support negative indexing for indexing from the end. There are probably
many others.

I'd love to see these supported. For this example:

enumerate(an_iterable, reversed=True)

would "just work" if an_iterable had a __len__ and a __getitem__.

It would raise a TypeError if passed a non-lengthed, or non-indexable
iterable.

-CHB

> > In short, this has nothing to do with reversed.

I agree.

>> If you made enumerate return a sequence when its input is a sequence,
you would also be able to do enumerate(some_list)[34],

As Chris A mentioned, it's quite easy to wrap list() or tuple() around it
if you want that.

- Chris B

-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GYMUOMMZJ7V5K2G7WQSOUNN5PZZG7DVE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 5:44 AM Neil Girdhar  wrote:
>
> On Thu, Jan 21, 2021 at 1:26 PM Chris Angelico  wrote:
> >
> > On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar  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.
>

With enumerate, you might be able to make a lazy sequence, but then
people will ask for map to be able to return a sequence too - and
that's going to definitely run into problems. It's much safer to be
explicit about it: if you want a list, ask for a list.

In the rare instances where you actually need an enumerated lazy list
(ie where the cost of an eager list is too high AND it needs to be
enumerated), it's not that hard to whip up a thing that gives back the
index as well:

class Enumerated:
def __init__(self, basis): self.basis = basis
def __getitem__(self, idx): return (idx, self.basis[idx])
def __len__(self): return len(self.basis)

That ought to do most or all of what you want. It's iterable and
reversible, and you can index it directly.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MFGKM6KBG3T4KMJCDRCWQMBFDB4D7OEC/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Neil Girdhar
On Thu, Jan 21, 2021 at 1:26 PM Chris Angelico  wrote:
>
> On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar  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 -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/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 
> python-ideas+unsubscr...@googlegroups.com.
> 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 -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RPKLUPE4XINPWKORTJU6TGUENPQ3UVXD/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Chris Angelico
On Fri, Jan 22, 2021 at 5:21 AM Neil Girdhar  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.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WW3JHS234TJSXKUICY4PG2SPDTD3SBUP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Neil Girdhar
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.

Best,

Neil
On Thursday, January 21, 2021 at 6:23:20 AM UTC-5 Nuri Jung wrote:

> So, what is the conclusion? I also think reversed(enumerate(some_seq)) 
> will be very useful in many cases.
> It should:
> 1) work the same as reversed(tuple(enumerate(...))) for "reversible" 
> objects as argument of enumerate,
> 2) raise TypeError if the object is not reversible.
>
> Or, another option would be adding a "step" keyword argument to enumerate.
> Then, reversing enumerate would be much easier, like this:
> enumerate(reversed(some_seq), step=-1)
> ___
> Python-ideas mailing list -- python...@python.org
> To unsubscribe send an email to python-id...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python...@python.org/message/BW2XKRZ4TSXCFULCS2EU33LLNMIXAL5T/
>  
> 
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YNJEP32X4VGD2GAMJCDJH6UHLBQHW5AP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: [Python-Dev] reversed enumerate

2021-01-21 Thread Nuri Jung
So, what is the conclusion? I also think reversed(enumerate(some_seq)) will be 
very useful in many cases.
It should:
1) work the same as reversed(tuple(enumerate(...))) for "reversible" objects as 
argument of enumerate,
2) raise TypeError if the object is not reversible.

Or, another option would be adding a "step" keyword argument to enumerate.
Then, reversing enumerate would be much easier, like this:
enumerate(reversed(some_seq), step=-1)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BW2XKRZ4TSXCFULCS2EU33LLNMIXAL5T/
Code of Conduct: http://python.org/psf/codeofconduct/