473,573 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ 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 2793
ia********@gmai l.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********@gmai l.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
2792
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 the email arrives, it has this information: v_firstname: asdf v_lastname: asdf b_email: asdf@bellsouth.net v_phone: asdf v_cellphone: asdf
5
8966
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 something more sophistictated like a vector of row objects. The data is of this format (same number of columns for each row): A, x, y, z, ...
11
5277
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 should configured to work, how memory is shared or not, etc. I can not seem to find any good links to this information. Thanks, Mike
1
3403
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. Does anyone have any ideas how to "select" multiple headers to sort on (as if it were a datasheet and you select multiple columns, then sort).
2
2046
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 (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
1
3699
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
0
5546
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
21101
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 sort the table based on 1 column works perfectly fine. dvShiftData is a DataView
4
4512
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 child apps of an IIS application and can be used by multiple users during the application life cycle and for multiple page loads for the same or...
0
7709
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8039
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8218
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8091
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3738
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3744
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1049
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.