Steven D'Aprano wrote:
On Mon, 20 Jun 2011 12:43:52 -0700, deathweaselx86 wrote:
I've been converting lists to sets, then back to lists again to get
unique lists.

I used to use list comps to do this instead.
foo = ['1','2','3']
bar = ['2','5']
foo.extend([a for a in bar if a not in foo]) foo
['1', '2', '3', '5']

Is there any performance hit to using one of these methods over the
other for rather large lists?

Absolutely!

For small lists, it really doesn't matter what you do. This probably only matters beyond a few tens of thousands of items.

Depends on the complexity of the object. It only took a couple thousand dbf records to notice a *huge* slowdown using 'in' tests on regular lists.

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to