Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-25 Thread Raymond Hettinger
On Jun 20, 9:43 pm, deathweaselx86 deathwea...@gmail.com wrote: Howdy guys, I am new. I've been converting lists to sets, then back to lists again to get unique lists. e.g Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type help, copyright,

Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread deathweaselx86
Howdy guys, I am new. I've been converting lists to sets, then back to lists again to get unique lists. e.g Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type help, copyright, credits or license for more information. foo = ['1','2','3'] bar =

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread Ian Kelly
On Mon, Jun 20, 2011 at 1:43 PM, deathweaselx86 deathwea...@gmail.com wrote: Howdy guys, I am new. I've been converting lists to sets, then back to lists again to get unique lists. e.g Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread Steven D'Aprano
On Mon, 20 Jun 2011 12:43:52 -0700, deathweaselx86 wrote: Howdy guys, I am new. I've been converting lists to sets, then back to lists again to get unique lists. e.g Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type help, copyright,

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread Ethan Furman
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

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread rusi
On Jun 21, 12:43 am, deathweaselx86 deathwea...@gmail.com wrote: Howdy guys, I am new. I've been converting lists to sets, then back to lists again to get unique lists. Maybe you should consider whether its best to work with sets only and not use lists at all. This needs to be said because: