Performance problem with filtering

Sheila King usenet at thinkspot.net
Thu Mar 14 00:42:23 EST 2002


On Thu, 14 Mar 2002 15:51:22 +1100, "Delaney, Timothy" <tdelaney at avaya.com>
wrote in comp.lang.python in article
<mailman.1016081544.20663.python-list at python.org>:

> > From: Sheila King [mailto:usenet at thinkspot.net]

> > How does something with list comprehensions compare? Like:
> > 
> > b = [entry for entry in b if entry not in a]
> > 
> > Is this as slow as the original method suggested? Or is it closer to
> > dictionary performance?
> 
> Essentially, that is identical to the original method. Simply expand it out
> ... (need to use a temporary name though).
> 
> temp_b = []
> 
> for entry in b:
>     if entry not in a:
>         temp_b.append(entry)
> 
> b = temp_b
> del temp_b

I understand how it works logically. I simply thought there might've been
some tricky C implementation of list comprehensions that improved
performance.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list