dict.has_key(x) versus 'x in dict'
Paul Melis
paul at floorball-flamingos.nl
Wed Dec 6 11:25:15 EST 2006
Bjoern Schliessmann wrote:
> Peter Otten wrote:
>
>> No, 'k in d' is equivalent to 'd.has_key(k)', only with less
>> (constant) overhead for the function call.
>
> Ah, thx. Thought the "x in d" syntax might search in d.values() too.
I don't think it does
Python 2.4.3 (#1, Nov 19 2006, 13:16:36)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d={1:'a',2:'b'}
>>> 1 in d
True
>>> 'a' in d
False
Paul
More information about the Python-list
mailing list