On Wed, Nov 5, 2008 at 10:03 PM, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
Only hashable objects can go in a set. By default a class you define is
not hashable (unless it descends from a hashable class). To remedy this
you can define a __hash__ method in your class. IIRC the only
The discussion's gone a bit off topic so I don't know if it is a good
idea to continue here. I'll try.
My first question was about a way to order a python set. Someone
suggested to try this module:
http://code.activestate.com/recipes/528878/
It seemed pretty good, but I've tried it just today
Mr.SpOOn [EMAIL PROTECTED] writes:
The discussion's gone a bit off topic so I don't know if it is a good
idea to continue here. I'll try.
My first question was about a way to order a python set. Someone
suggested to try this module:
http://code.activestate.com/recipes/528878/
It seemed
On Sun, 02 Nov 2008 02:08:37 +, Steven D'Aprano wrote:
On Sat, 01 Nov 2008 18:58:59 +, Tim Rowe wrote:
2008/10/27 [EMAIL PROTECTED]:
Lie Ryan:
Oh no, the two dict implementation would work _exactly_ the same from
the outside, they are transparently interchangeable. Only the
On Nov 4, 8:40 pm, Lie Ryan [EMAIL PROTECTED] wrote:
[snip]
On linguistic note: As a non-native speaker of English, I've never relied
on the correct usage of Yes and No and would instead rely on the
following text. In some languages, situations where English-people
usually use Yes is answered
On Mon, 27 Oct 2008 13:18:43 -0700, bearophileHUGS wrote:
So I don't accept so much different data structures to have the
same name
You need to adjust the current mindset slightly (but in an important way
to understand the why behind this idea). The current notion is: list
and dict is a
Lie Ryan:
Although you said you disagree with the general idea, you actually take the
idea two steps further, I take that as an implicit agreement to several parts
of the idea.
Think about a bridge: building half bridge may be bad/useless, while
building it whole may lead to something useful
2008/10/27 [EMAIL PROTECTED]:
Lie Ryan:
Oh no, the two dict implementation would work _exactly_ the same from the
outside, they are transparently interchangeable. Only the performance
characteristic differs because of the different implementation.
I don't agree with the general idea. If the
Lie Ryan wrote:
You need to adjust the current mindset slightly (but in an important way
to understand the why behind this idea). The current notion is: list
and dict is a data structure. With this idea, list and dict is an
abstract type, not a data structure. array, linked list, binary tree,
On Sat, 01 Nov 2008 18:58:59 +, Tim Rowe wrote:
2008/10/27 [EMAIL PROTECTED]:
Lie Ryan:
Oh no, the two dict implementation would work _exactly_ the same from
the outside, they are transparently interchangeable. Only the
performance characteristic differs because of the different
On Mon, 27 Oct 2008 17:03:58 -0700, Glenn Linderman wrote:
A little harder question is how to create a key that corresponds to
ascending string followed by descending string?
To do that you can sort the data two times, relying on the stable
nature of the Python sort.
Ick. Costs
Glenn Linderman:
how does one create a key that corresponds to ascending integer followed by
descending character string?
(Others may have already answered you because Google groups is very
slow.)
seq = [(10, abb), (5, zul), (5, hal), (2, of)]
sorted(seq, key=lambda (n,s): (-n, s),
[EMAIL PROTECTED] wrote:
Glenn Linderman:
how does one create a key that corresponds to ascending integer followed
by descending character string?
(Others may have already answered you because Google groups is very
slow.)
seq = [(10, abb), (5, zul), (5, hal), (2, of)]
sorted(seq,
Lie Ryan:
Oh no, the two dict implementation would work _exactly_ the same from the
outside, they are transparently interchangeable. Only the performance
characteristic differs because of the different implementation.
I don't agree with the general idea. If the operations done by your
data
On Oct 25, 4:58 am, Lie Ryan [EMAIL PROTECTED] wrote:
On Wed, 22 Oct 2008 10:43:35 -0700, bearophileHUGS wrote:
Mr.SpOOn:
Is there another convenient structure or shall I use lists and define
the operations I need?
musings
As Python becomes accepted for more and more serious projects
On approximately 10/27/2008 10:27 AM, came the following characters from
the keyboard of Peter Otten:
Here's a class that can negate arbitrary values
... def __init__(self, value):
... self.value = value
... def __cmp__(self, other):
... return -cmp(self.value,
On Sat, 25 Oct 2008 21:53:10 +, Lie Ryan wrote:
Oh no, the two dict implementation would work _exactly_ the same from
the outside, they are transparently interchangeable. Only the
performance characteristic differs because of the different
implementation.
They are not 100%
On Sun, 26 Oct 2008 00:53:18 +, Steven D'Aprano wrote:
[...]
And how do you find an arbitrary object's creation point without
searching the project's source code?
How is it better using the current way?
Asking the .implementation field isn't much harder than asking the type
(), and is much
On Sat, 25 Oct 2008 21:50:36 -0400, Terry Reedy wrote:
Lie Ryan wrote:
On Sat, 25 Oct 2008 18:20:46 -0400, Terry Reedy wrote:
Then why do you object to current
mylist = linkedlist(data)
and request the harder to write and implement
mylist = list(data, implementation =
On Wed, 22 Oct 2008 10:43:35 -0700, bearophileHUGS wrote:
Mr.SpOOn:
Is there another convenient structure or shall I use lists and define
the operations I need?
musings
As Python becomes accepted for more and more serious projects some
more data structures can eventually be added to the
On Sat, 25 Oct 2008 08:58:18 +, Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
b = dict({'a': 'A'}, implementation = 'binarytree')
c = dict({'a':
On Sat, 25 Oct 2008 09:21:05 +, Steven D'Aprano wrote:
On Sat, 25 Oct 2008 08:58:18 +, Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist') b =
Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
For this to work, the abstract list would have to know about all
implementations of the abstraction.
On Sat, 25 Oct 2008 18:20:46 -0400, Terry Reedy wrote:
Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
For this to work, the abstract list would
On Sat, 25 Oct 2008 18:20:46 -0400, Terry Reedy wrote:
Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
For this to work, the abstract list would
On Sat, 25 Oct 2008 21:53:10 +, Lie Ryan wrote:
On Sat, 25 Oct 2008 09:21:05 +, Steven D'Aprano wrote:
On Sat, 25 Oct 2008 08:58:18 +, Lie Ryan wrote:
anotherrandommusing
Since python is dynamic language, I think it should be possible to do
something like this:
a =
Lie Ryan wrote:
On Sat, 25 Oct 2008 18:20:46 -0400, Terry Reedy wrote:
a = list([1, 2, 3, 4, 5], implementation = 'linkedlist')
For this to work, the abstract list would have to know about all
implementations of the abstraction.
/the exact syntax isn't really important/
/abstract type and
Peter Otten [EMAIL PROTECTED] wrote:
I guess I have to move the goal posts to beat you:
set([-1,-2]), set([-2,-1])
(set([-2, -1]), set([-1, -2]))
For that one the number of slots doesn't matter because
hash(-1), hash(-2)
(-2, -2)
Neat.
last = []
for i in range(0,1,5):
Hi,
I need a structure to represent a set of integers. I also need to
perform on this set some basic set operations, such as adding or
removing elements, joining with other sets and checking for the
presence of specific elements.
I think that using Python sets would be the best choice, but I also
I think that using Python sets would be the best choice, but I also
need integers to be ordered inside the set and I've just found out
that, instead, Python sets are unordered collections.
Sets (both in Python, and their mathematical definition) are
unordered. However, some simple testing in
Tim Chase wrote:
Though for each test, in 2.3, 2.4, and 2.5 that I've got
installed on my local machine, they each printed s in-order,
and the iteration occurred in-order as well, even without the
added sorted(list(s)) code.
You need more tests then ;)
list(set([1,1000]))
[1000, 1]
By the
On Wed, Oct 22, 2008 at 3:37 PM, Peter Otten [EMAIL PROTECTED] wrote:
Tim Chase wrote:
Though for each test, in 2.3, 2.4, and 2.5 that I've got
installed on my local machine, they each printed s in-order,
and the iteration occurred in-order as well, even without the
added sorted(list(s))
In article [EMAIL PROTECTED],
Mr.SpOOn [EMAIL PROTECTED] wrote:
It seems to me that it orders elements when you add using the add()
method, but if you create a set starting from a list, it may result
unordered.
Arrrggghhh! None of these behaviors are guaranteed. The docs say, A set
object
On Wed, Oct 22, 2008 at 4:30 PM, Roy Smith [EMAIL PROTECTED] wrote:
In article [EMAIL PROTECTED],
Mr.SpOOn [EMAIL PROTECTED] wrote:
It seems to me that it orders elements when you add using the add()
method, but if you create a set starting from a list, it may result
unordered.
On Wed, 22 Oct 2008 15:37:03 +0200, Peter Otten [EMAIL PROTECTED] wrote:
Tim Chase wrote:
Though for each test, in 2.3, 2.4, and 2.5 that I've got
installed on my local machine, they each printed s in-order,
and the iteration occurred in-order as well, even without the
added sorted(list(s))
Peter Pearson wrote:
On Wed, 22 Oct 2008 15:37:03 +0200, Peter Otten [EMAIL PROTECTED] wrote:
Tim Chase wrote:
Though for each test, in 2.3, 2.4, and 2.5 that I've got
installed on my local machine, they each printed s in-order,
and the iteration occurred in-order as well, even without the
Mr.SpOOn:
Is there another convenient structure or shall I use lists and define
the operations I need?
musings
As Python becomes accepted for more and more serious projects some
more data structures can eventually be added to the collections
module:
- SortedSet, SortedDict: can be based on
Peter Otten [EMAIL PROTECTED] wrote:
Here's another one:
set([1,9])
set([1, 9])
set([9,1])
set([9, 1])
This time I did indeed search systematically...
You missed one with smaller values:
set([8,0])
set([8, 0])
set([0,8])
set([0, 8])
You can work some of it out quite easily instead
Duncan Booth wrote:
Peter Otten [EMAIL PROTECTED] wrote:
Here's another one:
set([1,9])
set([1, 9])
set([9,1])
set([9, 1])
This time I did indeed search systematically...
You missed one with smaller values:
set([8,0])
set([8, 0])
set([0,8])
set([0, 8])
I searched the minimal
39 matches
Mail list logo