473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2789
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
11
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings...
1
by: John | last post by:
(acc2002) I have a (continuous) subform (not datasheet) designed to look like columns of data. On each column "header" is a command button that when pressed, sort the records via that field. ...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: Hetal | last post by:
Hi... We are on Visual Basic .NET 2003 and i am using DataView to sort the DataTable. However, we are facing problems with sorting the data based on multiple columns. The below statement to...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.