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
> > 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)
> &
"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)
>
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
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
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
(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
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
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
>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
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".
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 "
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".
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
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
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
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
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
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
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
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
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
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
> >>
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'.
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
* 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
> * 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
* 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?
(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
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
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
> > 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'
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
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
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
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
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
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
Thanks Michael and Ant.
--
http://mail.python.org/mailman/listinfo/python-list
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
> "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
> I think it should be:
>
> if keyword.iskeyword(k):
> print k
Whoops - yes of course!
--
http://mail.python.org/mailman/listinfo/python-list
> 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
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
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
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
46 matches
Mail list logo