Why is if a in dict.keys() so slow.....
Richard Brodie
R.Brodie at rl.ac.uk
Thu Apr 13 06:45:02 EDT 2000
"Martin Franklin" <martin.franklin at waii.com> wrote in message
news:38F5A075.CDFA32D9 at bedford.waii.com...
> Just thought i'd throw this out there....
>
> This is very slow:-
>
> if split[0] in map_dict.keys():
>
> Compared to:-
>
> try:
> print 'found it!',map_dict[split[0]]
>
> The dictionary had about 40000 key:value pairs and I needed to
> look through it 250000 times.....
>
> Question is why?
I suppose creating a 40000 element list 250000 times might have
something to do with it. Have you tried map_dict.has_key(split[0]) ?
More information about the Python-list
mailing list