compound sorting in python -


I have a python script that receives a lot of data, the sample is given below 4 fields in the first Two letters, one digit, one slash, and one or two digits

  Gi3 / 2 -. -. -. -. - 0024.e89b C10e Dell Inc. Gi5 / 4 - - - - -. - 0030.c1cd.f038 HEWLETTPACKARD Gi4 / 3 - - - - -. - 0020.ac00.6703 Interface DATENSYSTEME GMBH Gi3 / 7 - -... -... - 0009.4392.34 F2 Cisco Systems Gia 6/6 - - - - - - 001c.2333. BD5A Dell Inc. G3/16 - - - - - -. 0009.7c92.7af2 Cisco Systems Givis / 5 - - - - - - - - 0020. ACACX 3.03 FB 0 Interface Diagnostic G G. 4/5 - - - - - - - - - - - - - - - - - - - - - - - - 0009.4392.6 DB2 Cisco Systems Guinea / 6 - - - - - - - 000b.cd39.c7c8 Hewlett Packard Gi6 / 4 - - - -. - 0021.70d7.8d33 Dell Inc. Gi6 / 14 - - - -.  

What would be the best way to sort this correctly on the first field, so that this sample can be read

 . Gi3 / 2 - - - - -. - 0024.e89b.c10e Dell Inc. Gio 3/7 -... -... - 0009.4392.34 F2 Cisco Systems G3/16 -----. ----- 0009.7c92.7af2 Cisco Systems Gaya 4/3 - - - - - - - 0020. ACAD 600.6703 I NTERFLEX DATENSYSTEME GMBH Gi4 / 5 - - - - - - - - 0009.4392.6db2 Cisco Systems Gi4 / 6 - - - - - 000b.cd39.c7c8 Hewlett Packard G4 4/4 - - -... - .-- 0030.c1cd.f038 Whitity Packard Gi5 / 12 - - - - - - 0020. ACAACAASX 3.0 GB Gi6 / 14 - - - - - -. 0009.7c91.fa71 Cisco Systems Gia 6/4 - - - - - - - 0021.70 D 7.8 D 33 Dell Ink Gia 6/6 - - - - - 001 C.233. BD5A Dell Inc  

My attempt has become very messy, and as a result 12 as before 12!

As always, many thanks for your patience.

  def line (line): keyStr, rest = line.split ('', 1 ) A, b = keyStr.split  
('/', 1) return (a, int (b)) sorted (line, key = line)

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -