Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Ron Adam <rrr@xxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 14:16:28 GMT
Antoon Pardon wrote:
Op 2005-08-31, Bengt Richter schreef <bokr@xxxxxx>:
On 31 Aug 2005 07:26:48 GMT, Antoon Pardon <apardon@xxxxxxxxxxxxxxx> wrote:
Op 2005-08-30, Bengt Richter schreef <bokr@xxxxxx>:
On 30 Aug 2005 10:07:06 GMT, Antoon Pardon <apardon@xxxxxxxxxxxxxxx> wrote:
Op 2005-08-30, Terry Reedy schreef <tjreedy@xxxxxxxx>:
"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xy86k3r7n.fsf@xxxxxxxxxxxxxxxxxxxxxx
Really it's x[-1]'s behavior that should go, not find/rfind.
I complete disagree, x[-1] as an abbreviation of x[len(x)-1] is extremely useful, especially when 'x' is an expression instead of a name.
I don't think the ability to easily index sequences from the right is in dispute. Just the fact that negative numbers on their own provide this functionality.
Because I sometimes find it usefull to have a sequence start and end at arbitrary indexes, I have written a table class. So I can have a table that is indexed from e.g. -4 to +6. So how am I supposed to easily get at that last value?
Give it a handy property? E.g.,
table.as_python_list[-1]
Your missing the point, I probably didn't make it clear.
It is not about the possibilty of doing such a thing. It is about python providing a frame for such things that work in general without the need of extra properties in 'special' cases.
How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ? That would give a consitent interpretation of seq[-1] and no errors for any value ;-)
But the question was not about having a consistent interpretation for -1, but about an easy way to get the last value.
But I like your idea. I just think there should be two differnt ways to index. maybe use braces in one case.
seq{i} would be pure indexing, that throws exceptions if you are out of bound
seq[i] would then be seq{i%len(seq)}
The problem with negative index's are that positive index's are zero based, but negative index's are 1 based. Which leads to a non symmetrical situations.
Note that you can insert an item before the first item using slices. But not after the last item without using len(list) or some value larger than len(list).
>>> a = list('abcde')
>>> a[len(a):len(a)] = ['end']
>>> a
['a', 'b', 'c', 'd', 'e', 'end']>>> a[-1:-1] = ['last'] >>> a ['a', 'b', 'c', 'd', 'e', 'last', 'end'] # Second to last.
>>> a[100:100] = ['final'] >>> a ['a', 'b', 'c', 'd', 'e', 'last', 'end', 'final']
Cheers, Ron
.
- References:
- Re: Bug in slice type
- From: bryanjugglercryptographer
- Re: Bug in slice type
- From: Steven Bethard
- Re: Bug in slice type
- From: Steven Bethard
- Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Bryan Olson
- Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Bryan Olson
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Steve Holden
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Bryan Olson
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Antoon Pardon
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Bryan Olson
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Steve Holden
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Bryan Olson
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Steve Holden
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing, was Re: Bug in slice type
- From: Antoon Pardon
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Terry Reedy
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Paul Rubin
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Terry Reedy
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Antoon Pardon
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Bengt Richter
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Antoon Pardon
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Bengt Richter
- Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- From: Antoon Pardon
- Re: Bug in slice type
- Prev by Date: Re: dynamicly updating an objects fields
- Next by Date: Re: Problem with string -> int conversion ?
- Previous by thread: Re: Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
- Next by thread: Infinity syntax. Re: Bug in string.find; was...
- Index(es):