Re: insert unique data in a list

2009-12-15 Thread Christian Tismer
On 12/14/09 2:24 AM, knifenomad wrote: On 12월14일, 오전10시19분, knifenomad wrote: On 12월14일, 오전2시57분, mattia wrote: Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: How can I insert non-duplicate data in a list? I mean, is there a particular option in the creat

Re: insert unique data in a list

2009-12-14 Thread mattia
Il Mon, 14 Dec 2009 21:53:38 +, Steven D'Aprano ha scritto: > On Mon, 14 Dec 2009 17:13:24 +, mattia wrote: > >> Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto: >> >>> On 12월14일, 오후12시42분, Steven D'Aprano >>> wrote: On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: >

Re: insert unique data in a list

2009-12-14 Thread Steven D'Aprano
On Mon, 14 Dec 2009 17:13:24 +, mattia wrote: > Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto: > >> On 12월14일, 오후12시42분, Steven D'Aprano >> wrote: >>> On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: >>> > this makes the set type hashable. >>> >>> > class Set(set): >>> >    

Re: insert unique data in a list

2009-12-14 Thread Lie Ryan
On 12/15/2009 4:13 AM, mattia wrote: > > of course it is broken as long as it uses it's instance id. i added this > to notify that unhashable can become hashable implementing __hash__ > inside the class. which probably set to None by default. Ok, nice example, but I believe that using id() as

Re: insert unique data in a list

2009-12-14 Thread mattia
Il Sun, 13 Dec 2009 21:17:28 -0800, knifenomad ha scritto: > On 12월14일, 오후12시42분, Steven D'Aprano > wrote: >> On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: >> > this makes the set type hashable. >> >> > class Set(set): >> >     __hash__ = lambda self: id(self) >> >> That's a *seriously* b

Re: insert unique data in a list

2009-12-13 Thread knifenomad
On 12월14일, 오후12시42분, Steven D'Aprano wrote: > On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: > > this makes the set type hashable. > > > class Set(set): > >     __hash__ = lambda self: id(self) > > That's a *seriously* broken hash function. > > >>> key = "voila" > >>> d = { Set(key): 1 } >

Re: insert unique data in a list

2009-12-13 Thread Steven D'Aprano
On Sun, 13 Dec 2009 17:19:17 -0800, knifenomad wrote: > this makes the set type hashable. > > class Set(set): > __hash__ = lambda self: id(self) That's a *seriously* broken hash function. >>> key = "voila" >>> d = { Set(key): 1 } >>> d {Set(['i', 'a', 'l', 'o', 'v']): 1} >>> d[ Set(key) ]

Re: insert unique data in a list

2009-12-13 Thread Lie Ryan
On 12/14/2009 11:49 AM, Fire Crow wrote: I also think that if every api has to conform to every other api nothing will ever get done. but if every object has its own distinct API, we will never finish reading the docs (assuming they do exist for each object). -- http://mail.python.org/mailman

Re: insert unique data in a list

2009-12-13 Thread Chris Rebert
On Sun, Dec 13, 2009 at 5:19 PM, knifenomad wrote: > On 12월14일, 오전2시57분, mattia wrote: >> Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: >> > How can I insert non-duplicate data in a list? I mean, is there a >> > particular option in the creation of a list that permit me not to use >> > s

Re: insert unique data in a list

2009-12-13 Thread knifenomad
On 12월14일, 오전10시19분, knifenomad wrote: > On 12월14일, 오전2시57분, mattia wrote: > > > > > > > Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: > > > > How can I insert non-duplicate data in a list? I mean, is there a > > > particular option in the creation of a list that permit me not to use > >

Re: insert unique data in a list

2009-12-13 Thread knifenomad
On 12월14일, 오전2시57분, mattia wrote: > Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: > > > How can I insert non-duplicate data in a list? I mean, is there a > > particular option in the creation of a list that permit me not to use > > something like: > > def append_unique(l, val): > >     if

Re: insert unique data in a list

2009-12-13 Thread Fire Crow
> Also, I'm not sure I like your abuse of the + operator to modify the > object in place and return a flag. It is an API not shared by (as far as > I can see) any other data type in Python. I agree it couuld be more consisten with other object apis, I also think that if every api has to conform t

Re: insert unique data in a list

2009-12-13 Thread geremy condra
On Sun, Dec 13, 2009 at 3:09 PM, Steven D'Aprano wrote: > On Sun, 13 Dec 2009 10:48:11 -0800, Fire Crow wrote: > >> You could also define a custom object that manages a custom ordered set > [...] >> I've used this on a few projects, it makes for wonderfully clean code, >> because you can look at y

Re: insert unique data in a list

2009-12-13 Thread Steven D'Aprano
On Sun, 13 Dec 2009 10:48:11 -0800, Fire Crow wrote: > You could also define a custom object that manages a custom ordered set [...] > I've used this on a few projects, it makes for wonderfully clean code, > because you can look at your program as an overview without all the > arithmetic behind it

Re: insert unique data in a list

2009-12-13 Thread Fire Crow
On Dec 13, 11:37 am, mattia wrote: > How can I insert non-duplicate data in a list? I mean, is there a > particular option in the creation of a list that permit me not to use > something like: > def append_unique(l, val): >     if val not in l: >         l.append(val) > > Thanks, > Mattia You cou

Re: insert unique data in a list

2009-12-13 Thread Andreas Waldenburger
On 13 Dec 2009 17:57:47 GMT mattia wrote: > Using set does'n work (i.e. the python interpreter tells me: > TypeError: unhashable type: 'list')... Convert the lists to tuples before adding them. Tuples are hashable. /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list

Re: insert unique data in a list

2009-12-13 Thread Gary Herron
mattia wrote: Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val)

Re: insert unique data in a list

2009-12-13 Thread mattia
Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: > How can I insert non-duplicate data in a list? I mean, is there a > particular option in the creation of a list that permit me not to use > something like: > def append_unique(l, val): > if val not in l: > l.append(val) > > Than

Re: insert unique data in a list

2009-12-13 Thread Alf P. Steinbach
* mattia: How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val) How about using a set instead? >>> a = {1, 2, 3} >>> a

Re: insert unique data in a list

2009-12-13 Thread Sean DiZazzo
On Dec 13, 8:37 am, mattia wrote: > How can I insert non-duplicate data in a list? I mean, is there a > particular option in the creation of a list that permit me not to use > something like: > def append_unique(l, val): >     if val not in l: >         l.append(val) > > Thanks, > Mattia Check ou

Re: insert unique data in a list

2009-12-13 Thread Gary Herron
mattia wrote: How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val) Thanks, Mattia Unless the insertion order is importa

insert unique data in a list

2009-12-13 Thread mattia
How can I insert non-duplicate data in a list? I mean, is there a particular option in the creation of a list that permit me not to use something like: def append_unique(l, val): if val not in l: l.append(val) Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list