nested exceptions?

Aahz aahz at pythoncraft.com
Sun Apr 21 10:22:45 EDT 2002


In article <roy-D4669D.09550721042002 at oldnews.panix.com>,
Roy Smith  <roy at panix.com> wrote:
>aahz at pythoncraft.com (Aahz) wrote:
>>
>> Hmmmm....  it occurs to me that those of us teaching Python will need to
>> be *very* careful in making sure that people avoid 'in' over lists.
>
>Why?

O(N*M)

That is, if you're checking N items against a list with M items, you're
gonna have poor performance algorithmically.  Note that I said "avoid";
using 'in' against a list is sometimes the simplest and most
straightforward approach, and if it's not being done in a loop, it won't
cause too much of a performance hit.

It wasn't such a big deal earlier, because it used to be we could just
say, "Don't use 'in' with loops," but now you *do* want to use for dicts
just about everywhere.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?



More information about the Python-list mailing list