Nick Coghlan wrote:
Stability in sorting is a property not to be sneezed at - it means
switching to sorting by a second key gives the effect of "sort by key 1,
then by key 2", whereas that doesn't hold with an unstable sort
Assuming "key 1" refers to the first key, and "key 2" to the second
key,
Jeff Shannon wrote:
> Jp Calderone wrote:
>
> > L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
> > L2.sort()
> > L = [d for (v, i, d) in L2]
>
> Out of curiosity, any reason that you're including the index? I'd
> have expected to just do
>
> L2 = [(d[key], d) for d in L]
>
Jeff Shannon wrote:
Agreed. I'd started typing before I realized that it'd provide a stable
sort, which pretty much answered my own question, but decided to send it
anyhow in case I'd missed anything else... :)
And it turns out we both missed the fact that it avoids comparing the
dictionaries w
Nick Coghlan wrote:
Jeff Shannon wrote:
I suppose that your version has the virtue that, if the sortkey value
is equal, items retain the order that they were in the original list,
whereas my version will sort them into an essentially arbitrary order.
Is there anything else that I'm missing here
Jeff Shannon wrote:
Jp Calderone wrote:
L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L2.sort()
L = [d for (v, i, d) in L2]
Out of curiosity, any reason that you're including the index?
Others have already remarked that this preserves sort stability
(which is, in fact a lovely proper
Craig Ringer wrote:
Well, that's several hundred more words than were probably required, but
I hope I made sense.
Remarkably similar to what I just posted. . . I guess numeric 2-tuples are just
too good to pass up when discussing sorting :)
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED]
[Nick Coghlan]
...
> Python 2.3 has a stable sort, and Python 2.4 brought the guarantee that it
> shall
> remain that way. I'm not sure about Python 2.2 and earlier.
No list.sort() implementation before 2.3 was stable. It was
confusing, though, because the samplesort/binary_insertion_sort hybrid
It's me wrote:
What does it mean by "stability in sorting"?
Can somebody please give a sample for using the code posted? I am a little
lost here and I like to know more about the use of keys
It's the jargon for what Jeff said - if you are sorting by some value calculated
from each list entry,
On Sat, 2005-01-08 at 00:26, It's me wrote:
> What does it mean by "stability in sorting"?
If I understand correctly, it means that when two sorts are performed in
sequence, the keys that are equal to the second sort end up ordered the
way they were left by the first sort.
I'm far from certain of
What does it mean by "stability in sorting"?
Can somebody please give a sample for using the code posted? I am a little
lost here and I like to know more about the use of keys
Thanks,
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jeff Shannon wrote:
> > I supp
Jeff Shannon wrote:
I suppose that your version has the virtue that, if the sortkey value is
equal, items retain the order that they were in the original list,
whereas my version will sort them into an essentially arbitrary order.
Is there anything else that I'm missing here?
Stability in sorti
Jp Calderone wrote:
L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L2.sort()
L = [d for (v, i, d) in L2]
Out of curiosity, any reason that you're including the index? I'd
have expected to just do
L2 = [(d[key], d) for d in L]
L2.sort()
L = [d for (v, d) in L2]
I suppose
Jp Calderone wrote:
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends <[EMAIL PROTECTED]> wrote:
Suppose I have a list of dictionaries and each dict has a common keyname
with a (sortable) value in it.
How can I shuffle their position in the list in such way that they
become sorted.
In Python 2.4
J Berends <[EMAIL PROTECTED]> writes:
> Suppose I have a list of dictionaries and each dict has a common
> keyname with a (sortable) value in it.
>
> How can I shuffle their position in the list in such way that they
> become sorted.
Do I understand the question right? Can't you just say
thel
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends <[EMAIL PROTECTED]> wrote:
>Suppose I have a list of dictionaries and each dict has a common keyname
> with a (sortable) value in it.
>
> How can I shuffle their position in the list in such way that they
> become sorted.
>
In Python 2.4,
im
Suppose I have a list of dictionaries and each dict has a common keyname
with a (sortable) value in it.
How can I shuffle their position in the list in such way that they
become sorted.
Maybe I am doing it wrongly and you would say: why don't you get
yourself a (slimmed-down) implementation of
16 matches
Mail list logo