Algorithm used by keyword 'in'
John Roth
newsgroups at jhrothjr.com
Sat Oct 9 11:06:33 EDT 2004
"Derek Rhodes" <rhoder at worldpath.net> wrote in message
news:lYS9d.144800$Kt5.79976 at twister.nyroc.rr.com...
> #using python 2.4a3
>
> say there is a list:
>
> list = range(10000)
>
> Now randomize it.
>
> Next, command the interpreter:
>
>>>> 465 in list
> True
>>>>
>
> What algorithm is used here?
"in" asks the object to determine if the
operand is in the object. Since this is
a list, it's probably using a sequential
search. If it was a dictionary, it would
use a keyword lookup, as you would
expect. For any other object, it will
do whatever that object wants.
John Roth
>
>
> -Derek.
>
>
More information about the Python-list
mailing list