From: Steve Holden on
samwyse wrote:
> On Jan 18, 1:56 am, Terry Reedy <tjre...(a)udel.edu> wrote:
>> On 1/17/2010 5:37 PM, samwyse wrote:
>>
>>
>>
>>
>>
>>> Consider this a wish list. I know I'm unlikely to get any of these in
>>> time for for my birthday, but still I felt the need to toss it out and
>>> see what happens.
>>> Lately, I've slinging around a lot of lists, and there are some simple
>>> things I'd like to do that just aren't there.
>>> s.count(x[, cmp[, key]])
>>> - return number of i�s for which s[i] == x. 'cmp' specifies a custom
>>> comparison function of two arguments, as in '.sort'. 'key' specifies
>>> a custom key extraction function of one argument.
>>> s.index(x[, i[, j[, cmp[, key]]]])
>>> - return smallest k such that s[k] == x and i<= k< j. 'cmp' and
>>> 'key' are as above.
>>> s.rindex(x[, i[, j[, cmp[, key]]]])
>>> - return largest k such that s[k] == x and i<= k< j. 'cmp' and
>>> 'key' are as above.
>>> There are two overlapping proposals here. One is to add the .rindex
>>> method, which strings already have. The other is to extend the
>>> optional arguments of .sort to all other methods that test for item
>>> equality.
>>> One last thing, the Python 2.6.2 spec says .count and .index only
>>> apply to mutable sequence types. I see no reason why they
>>> (and .rindex) couldn't also apply to immutable sequences (tuples, in
>>> particular).
>> In 3.x, tuple does have those methods, even though the doc is not clear
>> (unless fixed by now).
>
> That's good to hear. Perhaps I should have tried them directyly, but
> my 3.1 docs still echo the 2.x docs, which only show them for
> immutable sequences.

The tuple IS an immutable sequence.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

First  |  Prev  | 
Pages: 1 2 3
Prev: A simple-to-use sound file writer
Next: using super