Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57880 > unrolled thread
| Started by | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| First post | 2013-10-29 05:22 +0000 |
| Last post | 2013-11-06 11:15 -0800 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.python
Slicing with negative strides Steven D'Aprano <steve@pearwood.info> - 2013-10-29 05:22 +0000
Re: Slicing with negative strides Duncan Booth <duncan.booth@invalid.invalid> - 2013-10-29 08:53 +0000
Re: Slicing with negative strides Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-29 09:34 +0000
Re: Slicing with negative strides Terry Reedy <tjreedy@udel.edu> - 2013-10-29 06:21 -0400
Re: Slicing with negative strides Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-29 11:04 +0000
Re: Slicing with negative strides Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-29 08:54 +0000
Re: Slicing with negative strides Martin Manns <mmanns@gmx.net> - 2013-11-04 00:15 +0100
Re: Slicing with negative strides Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-04 15:18 +0000
Re: Slicing with negative strides Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-06 11:15 -0800
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2013-10-29 05:22 +0000 |
| Subject | Slicing with negative strides |
| Message-ID | <526f45f8$0$6512$c3e8da3$5496439d@news.astraweb.com> |
Does anyone here use slices (or range/xrange) with negative strides other than -1? E.g. sequence[2:15:-3] If so, there is a discussion (long, long, looooooong discussion) on the python-ideas mailing list, debating whether or not to deprecate or change the behaviour of slicing with negative strides. So if you care about the current behaviour, now is the time to stand up and be counted. (Standing up *here* is fine, don't feel that you have to join yet another list.) -- Steven
[toc] | [next] | [standalone]
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Date | 2013-10-29 08:53 +0000 |
| Message-ID | <XnsA26858FD6F7E7duncanbooth@127.0.0.1> |
| In reply to | #57880 |
Steven D'Aprano <steve@pearwood.info> wrote: > Does anyone here use slices (or range/xrange) with negative strides > other than -1? > > E.g. sequence[2:15:-3] With any negative stride your example is just the empty sequence. > > > If so, there is a discussion (long, long, looooooong discussion) on > the python-ideas mailing list, debating whether or not to deprecate or > change the behaviour of slicing with negative strides. So if you care > about the current behaviour, now is the time to stand up and be > counted. > > (Standing up *here* is fine, don't feel that you have to join yet > another list.) > For those of us that don't really want to join another mailing list, could you summarise what change is being proposed? -- Duncan Booth http://kupuguy.blogspot.com
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-10-29 09:34 +0000 |
| Message-ID | <mailman.1752.1383039312.18130.python-list@python.org> |
| In reply to | #57894 |
On 29/10/2013 08:53, Duncan Booth wrote: > Steven D'Aprano <steve@pearwood.info> wrote: > >> Does anyone here use slices (or range/xrange) with negative strides >> other than -1? >> >> E.g. sequence[2:15:-3] > > With any negative stride your example is just the empty sequence. > >> >> >> If so, there is a discussion (long, long, looooooong discussion) on >> the python-ideas mailing list, debating whether or not to deprecate or >> change the behaviour of slicing with negative strides. So if you care >> about the current behaviour, now is the time to stand up and be >> counted. >> >> (Standing up *here* is fine, don't feel that you have to join yet >> another list.) >> > For those of us that don't really want to join another mailing list, could > you summarise what change is being proposed? > Umpteen options have been put forward. IMHO the bookies favourite is currently being endorsed by Tim Peters and Terry Reedy, yours odds may vary :) -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-10-29 06:21 -0400 |
| Message-ID | <mailman.1753.1383042093.18130.python-list@python.org> |
| In reply to | #57894 |
On 10/29/2013 4:53 AM, Duncan Booth wrote: > Steven D'Aprano <steve@pearwood.info> wrote: > >> Does anyone here use slices (or range/xrange) with negative strides >> other than -1? >> >> E.g. sequence[2:15:-3] > > With any negative stride your example is just the empty sequence. The idea is that one would not have to reverse 2 and 15 to get a non-empty sequence. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-10-29 11:04 +0000 |
| Message-ID | <526f9635$0$29972$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #57894 |
On Tue, 29 Oct 2013 08:53:08 +0000, Duncan Booth wrote: > Steven D'Aprano <steve@pearwood.info> wrote: > >> Does anyone here use slices (or range/xrange) with negative strides >> other than -1? >> >> E.g. sequence[2:15:-3] > > With any negative stride your example is just the empty sequence. Gah, sorry about that, that's the suggested *new* syntax. Possibly my subconscious likes it better than my conscious :-) Try this instead: sequence[15:2:-3] >> If so, there is a discussion (long, long, looooooong discussion) on the >> python-ideas mailing list, debating whether or not to deprecate or >> change the behaviour of slicing with negative strides. So if you care >> about the current behaviour, now is the time to stand up and be >> counted. >> >> (Standing up *here* is fine, don't feel that you have to join yet >> another list.) >> > For those of us that don't really want to join another mailing list, > could you summarise what change is being proposed? * Negative strides should be deprecated and then removed. * Or just deprecated. * Or change the semantics of negative strides so that seq[2:15:-2] works as expected. * Or get rid of negative indexing. * Or add new syntax to control whether or not the end points are included. * Or ... It's Python-Ideas, otherwise known as Bike-Shed Central :-) I think the main idea which is likely (since Guido seems to be slightly leaning that way) is to deprecate negative strides, remove them in a release or three, and then re-introduce them in Python 4000 but with more intuitive semantics. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-10-29 08:54 +0000 |
| Message-ID | <mailman.1750.1383036893.18130.python-list@python.org> |
| In reply to | #57880 |
On 29/10/2013 05:22, Steven D'Aprano wrote: > Does anyone here use slices (or range/xrange) with negative strides other > than -1? > > E.g. sequence[2:15:-3] > In 10 ish years I don't recall ever considering it, let alone doing it. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Martin Manns <mmanns@gmx.net> |
|---|---|
| Date | 2013-11-04 00:15 +0100 |
| Message-ID | <20131104001540.02a6b9a4@Fuddel> |
| In reply to | #57880 |
On 29 Oct 2013 05:22:00 GMT Steven D'Aprano <steve@pearwood.info> wrote: > Does anyone here use slices (or range/xrange) with negative strides > other than -1? I have used negative strides for comparing discrete sequences e. g. for turbulence analysis, and I hope that my code will still run in Python 4. Martin
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-11-04 15:18 +0000 |
| Message-ID | <5277bac7$0$29972$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #58417 |
On Mon, 04 Nov 2013 00:15:40 +0100, Martin Manns wrote: > On 29 Oct 2013 05:22:00 GMT > Steven D'Aprano <steve@pearwood.info> wrote: > >> Does anyone here use slices (or range/xrange) with negative strides >> other than -1? > > I have used negative strides for comparing discrete sequences e. g. for > turbulence analysis, and I hope that my code will still run in Python 4. Can you show us a typical example of how you would normally use such negative strides? Thanks, -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Peter Cacioppi <peter.cacioppi@gmail.com> |
|---|---|
| Date | 2013-11-06 11:15 -0800 |
| Message-ID | <902d01b1-2261-4db1-b3e9-b1292ec77e1c@googlegroups.com> |
| In reply to | #57880 |
On Monday, October 28, 2013 10:22:00 PM UTC-7, Steven D'Aprano wrote: > Does anyone here use slices (or range/xrange) with negative strides other > > than -1? > Non default positive strides are very handy, but negative strides seem weird to me. Not the negative striding exactly, but the way fenceposts and negative strides interact. For example, this poster seems to posit a canonical WTF with negative strides. http://stackoverflow.com/questions/5798136/python-reverse-stride-slicing I can almost picture Picard saying "WTF do you need to omit the end index to get the zero element??!!" Readability counts, no? Just reverse it and use positive strides.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web