From: Stef Mientki on
On 21-04-2010 10:56, Chris Rebert wrote:
> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
>
>> With the following code, I would expect a result of 5 !!
>>
>>
>>>>> a= 'word1 word2 word3'
>>>>> a.rfind(' ',7)
>>>>>
>> 11
>>
>> Is this a bug ?
>>
> No. Don't you think someone would have found such an obvious bug by now?
>
if it's not a bug,
then the start index has no meaning ...
.... and some would call that a bug.

cheers,
Stef
From: Jean-Michel Pichavant on
Stef Mientki wrote:
> On 21-04-2010 10:56, Chris Rebert wrote:
>
>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
>>
>>
>>> With the following code, I would expect a result of 5 !!
>>>
>>>
>>>
>>>>>> a= 'word1 word2 word3'
>>>>>> a.rfind(' ',7)
>>>>>>
>>>>>>
>>> 11
>>>
>>> Is this a bug ?
>>>
>>>
>> No. Don't you think someone would have found such an obvious bug by now?
>>
>>
> if it's not a bug,
> then the start index has no meaning ...
> ... and some would call that a bug.
>
> cheers,
> Stef
>
a.rfind(' ', 12)
Out[12]: -1

looks like the start index has a meaning ...

JM

From: Chris Rebert on
On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
> On 21-04-2010 10:56, Chris Rebert wrote:
>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
>>> With the following code, I would expect a result of 5 !!
>>>
>>>>>> a= 'word1 word2 word3'
>>>>>> a.rfind(' ',7)
>>>>>>
>>> 11
>>>
>>> Is this a bug ?
>>>
>> No. Don't you think someone would have found such an obvious bug by now?
>>
> if it's not a bug,
> then the start index has no meaning ...
> ... and some would call that a bug.

Ah, I neglected to take your use of .rfind()'s second parameter into account!

As can be interpolated from the part of the docs James quotes:
s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not present' case

That is, the second parameter to .rfind(), namely `start`, is relative
to the *left* end of the string, not the right end. I can see how this
might be unintuitive, but it does make the API more uniform.

Cheers,
Chris
From: Alf P. Steinbach on
* Chris Rebert:
> On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
>> On 21-04-2010 10:56, Chris Rebert wrote:
>>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki <stef.mientki(a)gmail.com> wrote:
>>>> With the following code, I would expect a result of 5 !!
>>>>
>>>>>>> a= 'word1 word2 word3'
>>>>>>> a.rfind(' ',7)
>>>>>>>
>>>> 11
>>>>
>>>> Is this a bug ?
>>>>
>>> No. Don't you think someone would have found such an obvious bug by now?
>>>
>> if it's not a bug,
>> then the start index has no meaning ...
>> ... and some would call that a bug.
>
> Ah, I neglected to take your use of .rfind()'s second parameter into account!
>
> As can be interpolated from the part of the docs James quotes:
> s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not present' case
>
> That is, the second parameter to .rfind(), namely `start`, is relative
> to the *left* end of the string, not the right end. I can see how this
> might be unintuitive, but it does make the API more uniform.

It seems that the OP also thought it was relative to the left end of the string.

The difference is what it signifies: start of search, or end of search.

With rfind the "start" parameter signifies the end of the search, and
conversely, the third parameter "end" signifies where the search starts. :-)


Cheers,

- Alf
From: Stef Mientki on
On 21-04-2010 12:33, Alf P. Steinbach wrote:
> * Chris Rebert:
>> On Wed, Apr 21, 2010 at 2:59 AM, Stef Mientki
>> <stef.mientki(a)gmail.com> wrote:
>>> On 21-04-2010 10:56, Chris Rebert wrote:
>>>> On Wed, Apr 21, 2010 at 1:51 AM, Stef Mientki
>>>> <stef.mientki(a)gmail.com> wrote:
>>>>> With the following code, I would expect a result of 5 !!
>>>>>
>>>>>>>> a= 'word1 word2 word3'
>>>>>>>> a.rfind(' ',7)
>>>>>>>>
>>>>> 11
>>>>>
>>>>> Is this a bug ?
>>>>>
>>>> No. Don't you think someone would have found such an obvious bug by
>>>> now?
>>>>
>>> if it's not a bug,
>>> then the start index has no meaning ...
>>> ... and some would call that a bug.
>>
>> Ah, I neglected to take your use of .rfind()'s second parameter into
>> account!
>>
>> As can be interpolated from the part of the docs James quotes:
>> s.rfind(' ', 7) === s[7:].rfind(' ') + 7 # overlooking the 'not
>> present' case
>>
>> That is, the second parameter to .rfind(), namely `start`, is relative
>> to the *left* end of the string, not the right end. I can see how this
>> might be unintuitive, but it does make the API more uniform.
>
> It seems that the OP also thought it was relative to the left end of
> the string.
>
> The difference is what it signifies: start of search, or end of search.
>
> With rfind the "start" parameter signifies the end of the search, and
> conversely, the third parameter "end" signifies where the search
> starts. :-)
>
thanks Alf,
that's indeed what I was missing.

cheers,
Stef

>
> Cheers,
>
> - Alf