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
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:
>
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):
>>> >
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
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
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 }
>
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) ]
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
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
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
> >
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
> 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
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
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
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
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
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)
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
* 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
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
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
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
22 matches
Mail list logo