In article <[EMAIL PROTECTED]>,
Peter Maas <[EMAIL PROTECTED]> wrote:
> Antoon Pardon schrieb:
> > Dictionary lookup with mutable types like lists is a source of
> > unpleasant surprises for the programmer and therefore impossible in
> > Python.
> >
> >
> > It is not impossible in Python.
Antoon Pardon schrieb:
Dictionary lookup with mutable types like lists is a source of
unpleasant surprises for the programmer and therefore impossible in
Python.
It is not impossible in Python. It may be discouraged but it is not
impossible since I have already done so.
Wouldn't this raise a
Antoon Pardon wrote:
What are good arguments or bad and how much weight they have depends
on the person and on the circumstances. So a simple rule like:
Never use a mutable as a key in a dictionary will sometimes not be
the best solution.
True - but I think a purely identity based dictionary *is* t
Op 2005-01-14, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>
>> Op 2005-01-14, Peter Maas schreef <[EMAIL PROTECTED]>:
>>
>>>I have summarized the discussion about the usability of lists (and
>>>and other mutable types) as dictionary keys and put it into the
>>>Python wiki.URL
Peter Maas wrote:
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
Antoon Pardon wrote:
> I had a look and I think you should correct the followingr:
>
> D
Antoon Pardon wrote:
Op 2005-01-14, Peter Maas schreef <[EMAIL PROTECTED]>:
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
This summary might be used as a
"Peter Maas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
This summary might be used as a re
Op 2005-01-14, Peter Maas schreef <[EMAIL PROTECTED]>:
> I have summarized the discussion about the usability of lists (and
> and other mutable types) as dictionary keys and put it into the
> Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
>
> This summary might be used as a reference s
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
This summary might be used as a reference should the 'mutable
dictionary keys' issue come up again in c.l.py
Terry Reedy wrote:
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
This *is* a bug (since Guido called it such), but one not yet fixed as
the obvious solution (removing object.__hash__) causes problems for
Jython,
and a non-obvious solution has not been identified.
S
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This *is* a bug (since Guido called it such), but one not yet fixed as
> the obvious solution (removing object.__hash__) causes problems for
> Jython,
> and a non-obvious solution has not been identified.
Since object
On 2004-12-29 14:04:19, Nick Coghlan wrote:
> This *is* a bug (since Guido called it such), but one not yet fixed as the
> obvious solution (removing object.__hash__) causes problems for Jython, and
> a non-obvious solution has not been identified.
class object:
def __hash__(self):
Yeah, that looks like a pretty decent summary to me. I wonder if this
would be worth posting on the Wiki somewhere? Maybe:
http://www.python.org/moin/DictionaryKeys
That makes it easy to point to when this issue comes up again.
The page may also want to mention an extant bug with new-style clas
Peter Maas wrote:
Peter Maas schrieb:
There was a huge and sometimes heated debate about tuples, lists and
dictionaries recently, and the mainstream opinion was that dictionary
keys must not be mutable, so lists are not allowed as dictionary keys.
Warning, long posting (~ 100 lines)
[snip summary]
I think that's a good summary. The condensed
version is that the results of both __hash__() and
__cmp__() have to remain stable for dicts to work
as one would expect. __cmp__ doesn't do that
for lists, and it isn't defined by default for user
objects.
John Roth
"Peter Maas" <[EMAIL PROTECTED]> wrot
Peter Maas schrieb:
There was a huge and sometimes heated debate about tuples, lists and
dictionaries recently, and the mainstream opinion was that dictionary
keys must not be mutable, so lists are not allowed as dictionary keys.
Warning, long posting (~ 100 lines)
The existence of lists and tuples
John Roth schrieb:
No. The basic answer is that it's up to the object whether
it will allow itself to be used as a dictionary key. In other
words, if the designer of an object thinks it makes sense
for instances to be dictionary keys, then he can supply a
__hash__() method. If he doesn't, then he d
Peter Maas wrote:
Steven Bethard schrieb:
If lists were hashable, new programmers to Python would almost
certainly make mistakes like:
py> d = {[1, 2, 3]: 'abc'}
> The coder here almost certainly *doesn't* want that list to be compared
> by id. The only way to get a binding for that list woul
"Peter Maas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This leads to the question:
>
> Why does (t1 == t2 => d[t1] identical to d[t2]) hold for user defined
> objects and not for lists? My answer: because the cmp function looks at
> id() for user defined objects and at list co
"Peter Maas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
There was a huge and sometimes heated debate about tuples, lists and
dictionaries recently, and the mainstream opinion was that dictionary
keys must not be mutable, so lists are not allowed as dictionary keys.
BUT: objects ar
Steven Bethard schrieb:
If lists were hashable, new programmers to Python would almost certainly
make mistakes like:
py> d = {[1, 2, 3]: 'abc'}
> The coder here almost certainly *doesn't* want that list to be compared
> by id. The only way to get a binding for that list would be using the
> dict
Andrew Koenig:
> If d is a dict and t1 and t2 are tuples, and t1 == t2, then d[t1] and d[t2]
> are the same element.
So long as the elements of t1 and t2 are well-behaved.
>>> class Spam:
... def __hash__(self):
... return id(self)
... def __eq__(self, other):
... return True
...
>>
Andrew Koenig schrieb:
This strikes me because if one can do this with instances of user
defined classes why not with lists? Trying to use lists as dict
keys yields "TypeError: list objects are unhashable". So why are
list objects unhashable and user defined objects hashable? For
user defined objec
Peter Maas wrote:
This strikes me because if one can do this with instances of user
defined classes why not with lists? Trying to use lists as dict
keys yields "TypeError: list objects are unhashable". So why are
list objects unhashable and user defined objects hashable? For
user defined objects ha
"Peter Maas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This strikes me because if one can do this with instances of user
> defined classes why not with lists? Trying to use lists as dict
> keys yields "TypeError: list objects are unhashable". So why are
> list objects unhashab
25 matches
Mail list logo