index() of sequence type?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Feb 7 23:29:54 CET 2008


En Thu, 07 Feb 2008 20:13:00 -0200, Raymond Hettinger <python at rcn.com>  
escribió:

> On Feb 7, 1:57 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> Tuples are worse: they implement
>> __contains__ but not index. So you can say:
>>
>> py> 2 in (1,2,4,8)
>> True
>>
>> but not:
>>
>> py> (1,2,4,8).index(2)
>
> You must be using an old version of Python like 2.5 ;-)
>
> As of yesterday, Py2.6 has tuple.index() and tuple.count().
>
>   Python 2.6a0 (trunk:60638M, Feb  6 2008, 18:10:45)
>   [GCC 4.1.1 (Gentoo 4.1.1)] on linux2
>   >>> (1,2,4,8).index(2)
>   1

The Time Machine in action again!

-- 
Gabriel Genellina




More information about the Python-list mailing list