Re: Hashable object with self references OR how to create a tuple that refers to itself

2012-06-18 Thread Duncan Booth
Dieter Maurer wrote: > You can create a tuple in "C" and then put a reference to itself into > it, but I am quite convinced that you cannot do it in Python itself. > (Of course, you could use "cython" to generate C code with a source > language very similar to Python). I don't think you can even

RE: Hashable object with self references OR how to create a tuple that refers to itself

2012-06-15 Thread Prasad, Ramit
> > I am trying to create a collection of hashable objects, where each > > object contains references to > > other objects in the collection. The references may be circular. > > > > To simplify, one can define > > x= list() > > x.append(x) > &

Re: Hashable object with self references OR how to create a tuple that refers to itself

2012-06-15 Thread Dieter Maurer
"Edward C. Jones" writes: > I am trying to create a collection of hashable objects, where each > object contains references to > other objects in the collection. The references may be circular. > > To simplify, one can define > x= list() > x.append(x) >

Hashable object with self references OR how to create a tuple that refers to itself

2012-06-15 Thread Edward C. Jones
I am trying to create a collection of hashable objects, where each object contains references to other objects in the collection. The references may be circular. To simplify, one can define x= list() x.append(x) which satisfies x == [x]. Can I create a similar object for tuples which

Re: confusing doc: mutable and hashable

2012-04-29 Thread Terry Reedy
On 4/29/2012 3:57 AM, John O'Hagan wrote: How do function objects fit into this scheme? They have __hash__, __eq__, seem to work as dict keys and are mutable. Is it because their hash value doesn't change? I suspect functions use the default equality and hash based on id, which does not chang

Re: confusing doc: mutable and hashable

2012-04-29 Thread John O'Hagan
s > [emphasis added]: > > "If a class defines *mutable* objects and implements a __cmp__() or > __eq__() method, it *should not* implement __hash__(), since hashable > collection implementations require that a object’s hash value is > immutable (if the object’s hash value chan

Re: confusing doc: mutable and hashable

2012-04-28 Thread Arnaud Delobelle
(sent from my phone) On Apr 28, 2012 7:36 PM, "Chris Rebert" wrote: > Correct. Pedantically, you can define __hash__() on mutable objects; > it's just not very useful or sensible, so people generally don't. I find it's fine to define __hash__ on mutable objects as long as __eq__ only relies on im

Re: confusing doc: mutable and hashable

2012-04-28 Thread Terry Reedy
On 4/28/2012 2:09 PM, laymanzh...@gmail.com wrote: In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable". According the wiki: http://en.wikipedia.org/wiki/Immutable_object In object-oriented and

Re: confusing doc: mutable and hashable

2012-04-28 Thread MRAB
On 28/04/2012 23:30, Temia Eszteri wrote: Yes, you're right. Being mutable and hashable are orthogonal properties. The implication mutable => non hashable is just a design choice. The reason for such a choice is the following. If a key-element pair K:X is added to a container C an

Re: confusing doc: mutable and hashable

2012-04-28 Thread Temia Eszteri
>Yes, you're right. Being mutable and hashable are orthogonal properties. >The implication > mutable => non hashable >is just a design choice. > >The reason for such a choice is the following. If a key-element pair K:X >is added to a container C and then K is ch

Re: confusing doc: mutable and hashable

2012-04-28 Thread Kiuhnm
On 4/28/2012 20:09, laymanzh...@gmail.com wrote: I'm just learning Python. The python doc about mutable and hashable is confusing to me. In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable".

Re: confusing doc: mutable and hashable

2012-04-28 Thread Chris Rebert
On Sat, Apr 28, 2012 at 11:09 AM, wrote: > I'm just learning Python. The python doc about mutable and hashable is > confusing to me. > > In my understanding, there is no directly relation between mutable and > hashable in Python. Any class with __hash__ function is "

Re: confusing doc: mutable and hashable

2012-04-28 Thread mwilson
laymanzh...@gmail.com wrote: > I'm just learning Python. The python doc about mutable and hashable is > confusing to me. > > In my understanding, there is no directly relation between mutable and > hashable in Python. Any class with __hash__ function is "hashable".

confusing doc: mutable and hashable

2012-04-28 Thread laymanzheng
I'm just learning Python. The python doc about mutable and hashable is confusing to me. In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable". According the wiki: http://en.wikipedia.org/wiki/I

Non hashable object (without __dict__)

2011-04-20 Thread Arthur Mc Coy
Hello, I have a C++ application, I used SWIG to call the python code. I pass myModule.myObject object to the method of python code and what to store it in JSON format. The problem is when I do: o = myModule.myObject() inside python, the o object has __dict__ property, but if I take the passed

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-10 Thread Syeberman
On Nov 8, 3:42 pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. > The short answer isn't entirely correct, however. Tuples are only hashable so lo

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Wells
On Nov 8, 2:42 pm, Mick Krippendorf wrote: > Wells wrote: > > I'm not quite understanding why a tuple is hashable but a list is not. > > The short answer has already been given. Here is the long answer: > > For objects p and q, p==q implies hash(p)==hash(q). It is esse

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Mick Krippendorf
Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. The short answer has already been given. Here is the long answer: For objects p and q, p==q implies hash(p)==hash(q). It is essential for dicts and sets that objects used as keys/elements uphold this

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread MRAB
Wells wrote: I'm not quite understanding why a tuple is hashable but a list is not. Any pointers? Thanks! A hash is created from the object. If the object is mutable then the hash can change. Lists are mutable but tuples aren't. -- http://mail.python.org/mailman/listinfo/python-list

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Tycho Andersen
On Sun, 8 Nov 2009, Wells wrote: I'm not quite understanding why a tuple is hashable but a list is not. Any pointers? Thanks! The keys of a dict have to be immutable. Lists are mutable, tuples are not. \t -- http://mail.python.org/mailman/listinfo/python-list

Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Dj Gilcrease
On Sun, Nov 8, 2009 at 11:15 AM, Wells wrote: > I'm not quite understanding why a tuple is hashable but a list is not. > Any pointers? Thanks! tuple is hashable because it is immutable whereas a list is mutable. -- http://mail.python.org/mailman/listinfo/python-list

list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Wells
I'm not quite understanding why a tuple is hashable but a list is not. Any pointers? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: are user defined classes hashable?

2009-07-21 Thread Hyuga
On Jul 20, 10:53 pm, a...@pythoncraft.com (Aahz) wrote: > In article <373d6c69-6965-4a88-bdd2-8028ef850...@k6g2000yqn.googlegroups.com>, > > Hyuga   wrote: > > >Regardless, Nicolas's example can be applied to the class too: > > class Foo(object): > >    pass > > hash(Foo) > >11443104 > >>

Re: are user defined classes hashable?

2009-07-20 Thread Aahz
In article <373d6c69-6965-4a88-bdd2-8028ef850...@k6g2000yqn.googlegroups.com>, Hyuga wrote: > >Regardless, Nicolas's example can be applied to the class too: > class Foo(object): > pass > hash(Foo) >11443104 id(Foo) >11443104 > >class objects are just objects of type 'type'.

Re: are user defined classes hashable?

2009-07-20 Thread Hyuga
On Jul 19, 11:39 am, Nicolas Dandrimont wrote: > * Alan G Isaac [2009-07-19 14:46:12 +]: > > > Again, my question is about the class not its instances, > > but still, checking as you suggest gives the same answer. > > That's what I get for answering before my coffee! Regardless, Nicolas's ex

Re: are user defined classes hashable?

2009-07-19 Thread Nicolas Dandrimont
* Alan G Isaac [2009-07-19 14:46:12 +]: > Again, my question is about the class not its instances, > but still, checking as you suggest gives the same answer. That's what I get for answering before my coffee! Cheers, -- Nicolas Dandrimont "Linux poses a real challenge for those with a ta

Re: are user defined classes hashable?

2009-07-19 Thread Alan G Isaac
> * Alan G Isaac [2009-07-19 13:48:16 +]: >> Are user defined classes hashable? >> (The classes; *not* the instances!) >> I'm inclined to guess it will be hashed by id and this is >> OK. On 7/19/2009 10:07 AM Nicolas Dandrimont apparently wrote: > Y

Re: are user defined classes hashable?

2009-07-19 Thread Nicolas Dandrimont
* Alan G Isaac [2009-07-19 13:48:16 +]: > Are user defined classes hashable? > (The classes; *not* the instances!) > > I want to use some classes as dictionary keys. > Python is not objecting, > but I'm not sure how to think about > whether this could be dangerou

are user defined classes hashable?

2009-07-19 Thread Alan G Isaac
Are user defined classes hashable? (The classes; *not* the instances!) I want to use some classes as dictionary keys. Python is not objecting, but I'm not sure how to think about whether this could be dangerous. I'm inclined to guess it will be hashed by id and this is OK. Than

Re: Doing set operation on non-hashable objects

2008-12-28 Thread 5lvqbwl02
icts. > > A function searches through db and returns a list of values, each of > > which is a dict as described above. > > I need to perform set operations on these lists (intersection and > > union) > > However the objects themselves are not hashable, and therefore ca

Re: Doing set operation on non-hashable objects

2008-12-28 Thread 5lvqbwl02
t; > However the objects themselves are not hashable, and therefore can't > > be in a set, because they are dicts. > > I'm not sure how large each set will be, but the point is I'm trying > > to avoid anything looking like an O(n^2) algorithm, so I can't just

Re: Doing set operation on non-hashable objects

2008-12-26 Thread 5lvqbwl02
> > A function searches through db and returns a list of values, each of > > which is a dict as described above. > > I need to perform set operations on these lists (intersection and > > union) > > However the objects themselves are not hashable, and therefore can'

Re: Doing set operation on non-hashable objects

2008-12-24 Thread Carl Banks
ch is a dict as described above. > I need to perform set operations on these lists (intersection and > union) > However the objects themselves are not hashable, and therefore can't > be in a set, because they are dicts. > I'm not sure how large each set will be, but the

Re: Doing set operation on non-hashable objects

2008-12-24 Thread Scott David Daniels
themselves are not hashable, and therefore can't be in a set, because they are dicts. I'm not sure how large each set will be, but the point is I'm trying to avoid anything looking like an O(n^2) algorithm, so I can't just use naive double-looping to check for intersection/union

Re: Doing set operation on non-hashable objects

2008-12-24 Thread Gabriel Genellina
ct as described above. I need to perform set operations on these lists (intersection and union) However the objects themselves are not hashable, and therefore can't be in a set, because they are dicts. See this thread from last week: http://groups.google.com/group/comp.lang.python/t/d6818ff713b

Doing set operation on non-hashable objects

2008-12-24 Thread 5lvqbwl02
ction and union) However the objects themselves are not hashable, and therefore can't be in a set, because they are dicts. I'm not sure how large each set will be, but the point is I'm trying to avoid anything looking like an O(n^2) algorithm, so I can't just use naive doubl

Re: Hashable

2008-01-26 Thread Steven D'Aprano
On Sat, 26 Jan 2008 11:10:03 +, Simon Pickles wrote: > Hi, > > The term 'hashable'. > > Am I right in thinking it means it can be indexed? like a string or a > dict? No. A hash function is a function which takes an arbitrary object and generates an integer

Hashable

2008-01-26 Thread Simon Pickles
Hi, The term 'hashable'. Am I right in thinking it means it can be indexed? like a string or a dict? Thanks Si -- Linux user #458601 - http://counter.li.org. -- http://mail.python.org/mailman/listinfo/python-list

Re: List objects are un-hashable

2007-04-29 Thread Andy
Thanks Michael and Ant. -- http://mail.python.org/mailman/listinfo/python-list

Re: List objects are un-hashable

2007-04-27 Thread Michael Hoffman
Andy wrote: > Hi, I'm trying to search and print any no# of Python keywords present > in a text file (say - foo.txt), and getting the above error. Sad for > not being able to decipher such a simple problem (I can come up with > other ways - but want to fix this one FFS). It helps a lot of if you p

Re: List objects are un-hashable

2007-04-27 Thread Ganesan Rajagopal
> "Andy" == Andy <[EMAIL PROTECTED]> writes: > if keyword.iskeyword(tempwords): > print tempwords for word in tempwords: if keyword.iskeyword(word): print word Ganesan -- Ganesan Rajagopal -- http://mail.python.org/mailman/listinfo/python-list

Re: List objects are un-hashable

2007-04-27 Thread Ant
> I think it should be: > > if keyword.iskeyword(k): > print k Whoops - yes of course! -- http://mail.python.org/mailman/listinfo/python-list

Re: List objects are un-hashable

2007-04-27 Thread Andy
> What you want is something like: > > for line in inp: > lines +=1 > # a list of words > tempwords = line.split() > for k in tempwords: > if keyword.iskeyword(k): > print tempwords I think it should be: if keyword.iskeyword(k): print k

Re: List objects are un-hashable

2007-04-27 Thread Ant
iskeyword function which converts the keyword list into a frozenset (in which elements must be hashable) for, I presume, performance reasons: >>> f_set = frozenset((1,2,3,4)) >>> ["test"] in f_set Traceback (most recent call last): File "", line 1, in

Re: List objects are un-hashable

2007-04-27 Thread Alexander Schmolck
Andy <[EMAIL PROTECTED]> writes: > Hi, I'm trying to search and print any no# of Python keywords present > in a text file (say - foo.txt), and getting the above error. Sad for > not being able to decipher such a simple problem (I can come up with Without looking at the docs, it seems save to assu

List objects are un-hashable

2007-04-27 Thread Andy
Hi, I'm trying to search and print any no# of Python keywords present in a text file (say - foo.txt), and getting the above error. Sad for not being able to decipher such a simple problem (I can come up with other ways - but want to fix this one FFS). Any help is appreciated. Thanks!! import keywo