470,836 Members | 1,897 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,836 developers. It's quick & easy.

Help with multiple key sort

gurus:

I want to implement a sql-like sort-by on multiple keys. I've seen
many examples of just two keys.

I have a list like this

1 one 2
1 one 1
1 two 1
1 one 0
1 xx 0

result should be like this

1 four 2
1 one 0
1 one 1
1 one 2
1 xx 0

It moves right while keeping sorted order to the left. This is the
new stable sort in 2.5.

I'm not sure what I'm doing wrong. please help.

Thanks

Feb 6 '07 #1
3 2651
ia********@gmail.com writes:
It moves right while keeping sorted order to the left. This is the
new stable sort in 2.5.
>>b
['1 one 2', '1 one 1', '1 two 1', '1 one 0', '1 xx 0']
>>sorted(b,key=lambda x: x.split())
['1 one 0', '1 one 1', '1 one 2', '1 two 1', '1 xx 0']
Feb 6 '07 #2
ia********@gmail.com kirjoitti:
gurus:

I want to implement a sql-like sort-by on multiple keys. I've seen
many examples of just two keys.

I have a list like this

1 one 2
1 one 1
1 two 1
1 one 0
1 xx 0

result should be like this

1 four 2
1 one 0
1 one 1
1 one 2
1 xx 0

It moves right while keeping sorted order to the left. This is the
new stable sort in 2.5.

I'm not sure what I'm doing wrong. please help.

Thanks
I'm not a guru. Maybe that's why I don't understand which "sql-like
sort-by on multiple keys" would produce output that lacks some of the
input but has additional items. ;)

In other words: why don't you show your concrete program and the input
and output data to use. Is the data a list of tuples or lists or what?

Cheers,
Jussi
Feb 6 '07 #3
Paul already answered it. Tnx Paul. My data is in a file and now I
have to take care to strip \t and \n from it.

Thanks
I'm not a guru. Maybe that's why I don't understand which "sql-like
sort-by on multiple keys" would produce output that lacks some of the
input but has additional items. ;)

In other words: why don't you show your concrete program and the input
and output data to use. Is the data a list of tuples or lists or what?

Cheers,
Jussi

Feb 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mcp6453 | last post: by
5 posts views Thread by Dr. Ann Huxtable | last post: by
2 posts views Thread by Daniel | last post: by
1 post views Thread by Rahul | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.