Thank you everyone for the assistance and for the very informative
discussion
Regards
SM
--
http://mail.python.org/mailman/listinfo/python-list
En Thu, 20 Sep 2007 08:46:29 -0300, Steven D'Aprano
[EMAIL PROTECTED] escribi�:
Another way is to use this class:
class HashableList(list):
def __hash__(self):
return hash(tuple(self))
...and that will stop working as soon as the list is mutated (which is
exactly what you
Gabriel Genellina wrote:
En Thu, 20 Sep 2007 08:46:29 -0300, Steven D'Aprano
Another way is to use this class:
class HashableList(list):
def __hash__(self):
return hash(tuple(self))
...and that will stop working as soon as the list is mutated (which is
exactly what you
On Sep 20, 5:02 am, Karthik Gurusamy [EMAIL PROTECTED] wrote:
In the new model, at the time of addition, you need to remember the
key at that time. If it's a list, you make a copy of the items.
In other words you ask the dict to freeze any mutable keys given to
it.
Try an implementation and you
On Sep 20, 4:17 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
[...]
Data structures don't have problems. Programmers do.
That's QOTW material :-)
... And language
designers with sense build languages that minimize the programmers
problems, not maximize them.
...
The
On Thu, 20 Sep 2007 03:46:08 +, prikar20 wrote:
On Sep 19, 5:25 pm, Mark Dickinson [EMAIL PROTECTED] wrote:
On Sep 19, 7:26 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote:
If I did, a = [10, 20] and I did d[a]= 'foo', then a.append(30).
If dict complains key error on d[a] now, I won't be
On Sep 20, 6:02 am, Karthik Gurusamy [EMAIL PROTECTED] wrote:
On Sep 19, 7:17 pm, Steven D'Aprano [EMAIL PROTECTED]
[...]
(2) Allow the hash of mutable objects to change, which means you can use
mutable objects as keys in dicts but if you change them, you can no
longer find them in the
On Sep 20, 9:50 am, thebjorn [EMAIL PROTECTED]
wrote:
it's bad form to reply to myself, I know, but
def __iter__(self):
for k in super(mdict,self).__iter__():
yield eval(k)
should probably be
def __iter__(self):
return (eval(k) for k in
Karthik Gurusamy wrote:
On Sep 19, 7:17 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
On Wed, 19 Sep 2007 20:58:03 +, Karthik Gurusamy wrote:
While it's easy to explain the behavior, I think the decision to dis-
allow mutable items as keys is a bit arbitrary. There is no
On Sep 19, 10:58 pm, Bryan Olson [EMAIL PROTECTED] wrote:
Bad news: Python 3000 has no immutable type for byte-strings.
The new bytes type cannot serve for dict keys or set members.
Many things one would want to hash are unhashable -- for
example, the results of the hash functions in hashlib.
On Thu, 20 Sep 2007 04:02:03 +, Karthik Gurusamy wrote:
On Sep 19, 7:17 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
On Wed, 19 Sep 2007 20:58:03 +, Karthik Gurusamy wrote:
While it's easy to explain the behavior, I think the decision to dis-
allow mutable items
Steven D'Aprano [EMAIL PROTECTED] (SD) wrote:
SD In other words, if you have two mutable objects M1 and M2, then you
SD expect:
SD hash(M1) == hash(M2) if and only if M1 and M2 are equal
SD hash(M1) != hash(M2) if M1 and M2 are unequal
Huh? Unequal things may hash to the same value. That one
On 2007-09-20, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
In the new model, it should be the value at the time of
addition. That is [1,2] (not [1,2,3]). This does mean a copy
of key in maintained internally in the dict.
A copy!? That has to be a deep copy. Which would make
`dict`\s
Steven D'Aprano wrote:
But of course you can't look up the dict by value, only by
identity. But that's what you wanted.
Actually, if I understand the OP's examples right, he wants to look
up only by value, not by identity.
--
--OKB (not okblacke)
Brendan Barnwell
Do not follow where
On 9/20/07, Dustan [EMAIL PROTECTED] wrote:
On Sep 19, 10:58 pm, Bryan Olson [EMAIL PROTECTED] wrote:
Bad news: Python 3000 has no immutable type for byte-strings.
The new bytes type cannot serve for dict keys or set members.
Many things one would want to hash are unhashable -- for
On 9/20/07, OKB (not okblacke) [EMAIL PROTECTED] wrote:
Steven D'Aprano wrote:
But of course you can't look up the dict by value, only by
identity. But that's what you wanted.
Actually, if I understand the OP's examples right, he wants to look
up only by value, not by identity.
Chris Mellon [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
| On 9/20/07, Dustan [EMAIL PROTECTED] wrote:
| On Sep 19, 10:58 pm, Bryan Olson [EMAIL PROTECTED] wrote:
| Bad news: Python 3000 has no immutable type for byte-strings.
| The new bytes type cannot serve for dict keys or
On Sep 19, 1:59 am, Raymond Hettinger [EMAIL PROTECTED] wrote:
On Sep 18, 5:39 pm, sapsi [EMAIL PROTECTED] wrote:
I recently tried using the set function in Python and was surprised to
find that
a=[ 1, 2,3, [1,2] ]
doesn't work with 'set', throwing TyperError (unhashable exception). I
On 9/19/07, Paddy [EMAIL PROTECTED] wrote:
frozenset over turning the embedded list into a tuple?
The tuple would preserve order in the item (1,2)
a = set([1,2,3, (1,2)])
The OP was probably thinking in mathematical terms as in the set of
all the possible subsets of the set composed by 1,
sapsi [EMAIL PROTECTED] wrote:
Why can't lists be hashed?
Several people have answered because they're mutable without
explaining why mutability precludes hashing. So:
Consider a dict (dicts have been in Python a *lot* longer than
sets, and have the same restriction) which allowed lists as
On Sep 19, 6:16 am, Sion Arrowsmith [EMAIL PROTECTED]
wrote:
sapsi [EMAIL PROTECTED] wrote:
Why can't lists be hashed?
Several people have answered because they're mutable without
explaining why mutability precludes hashing. So:
Consider a dict (dicts have been in Python a *lot* longer
On Sep 19, 9:58 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote:
Since we know hashing is used, all that is needed is, a well-defined
way to construct a hash out of a mutable. Given a sequence, how to
get a hash is the problem. If later the given sequence is different,
that's not the dict's
On Sep 19, 3:06 pm, Paddy [EMAIL PROTECTED] wrote:
On Sep 19, 9:58 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote:
Since we know hashing is used, all that is needed is, a well-defined
way to construct a hash out of a mutable. Given a sequence, how to
get a hash is the problem. If later the
On Sep 19, 7:26 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote:
If I did, a = [10, 20] and I did d[a]= 'foo', then a.append(30).
If dict complains key error on d[a] now, I won't be surprised. If I do
d[[10, 20, 30]], I will be surprised if it doesn't find the item. Of
course, in today's behavior
On Wed, 19 Sep 2007 20:58:03 +, Karthik Gurusamy wrote:
While it's easy to explain the behavior, I think the decision to dis-
allow mutable items as keys is a bit arbitrary. There is no need for
dict to recompute hash
What???
Of course it does. How else can it look up the key? Because
On Sep 19, 5:25 pm, Mark Dickinson [EMAIL PROTECTED] wrote:
On Sep 19, 7:26 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote:
If I did, a = [10, 20] and I did d[a]= 'foo', then a.append(30).
If dict complains key error on d[a] now, I won't be surprised. If I do
d[[10, 20, 30]], I will be
Karthik Gurusamy wrote:
While it's easy to explain the behavior, I think the decision to dis-
allow mutable items as keys is a bit arbitrary.
Furthermore, it's not really true.
class Blurf (object):
def __init__(self, intval):
self.seti(intval)
def
On Sep 19, 7:17 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
On Wed, 19 Sep 2007 20:58:03 +, Karthik Gurusamy wrote:
While it's easy to explain the behavior, I think the decision to dis-
allow mutable items as keys is a bit arbitrary. There is no need for
dict to
Hello,
I recently tried using the set function in Python and was surprised to
find that
a=[ 1, 2,3, [1,2] ]
doesn't work with 'set', throwing TyperError (unhashable exception). I
found out that this is because lists can't be hashed.
So,this implies 'a' cannot be a set in python which i think is
sapsi wrote:
2) This is not related, but is there i neat way (without pop and list
comprehension) to convert a set into a list? I say neat because i'm
guessing using list comprehension might turn out be slow and there
might be other methods which are faster.
a = set([1, 2, 3, 4])
b = list(a)
On Sep 18, 5:39 pm, sapsi [EMAIL PROTECTED] wrote:
I recently tried using the set function in Python and was surprised to
find that
a=[ 1, 2,3, [1,2] ]
doesn't work with 'set', throwing TyperError (unhashable exception). I
found out that this is because lists can't be hashed.
So,this
On Sep 19, 10:39 am, sapsi [EMAIL PROTECTED] wrote:
My question is,
1) Why can't lists be hashed?
They are mutable.
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 18, 7:39 pm, sapsi [EMAIL PROTECTED] wrote:
Hello,
I recently tried using the set function in Python and was surprised to
find that
a=[ 1, 2,3, [1,2] ]
doesn't work with 'set', throwing TyperError (unhashable exception). I
found out that this is because lists can't be hashed.
33 matches
Mail list logo