473,575 Members | 3,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l sort

How do I sort this:
[['3', ['1', '0']], ['4', ['3', '0'], ['2', '0']]]

where the list can be arbitrarily large by the 3rd dimension (i
think). E.g.:
[['3', ['1', '0']], ['4', ['2', '0'], ['3', '0']]]

Oct 10 '07 #1
1 1140
On Oct 10, 8:47 pm, termiflyer <dpfl...@earthl ink.netwrote:
How do I sort this:

[['3', ['1', '0']], ['4', ['3', '0'], ['2', '0']]]

where the list can be arbitrarily large by the 3rd dimension (i
think). E.g.:

[['3', ['1', '0']], ['4', ['2', '0'], ['3', '0']]]
There's no canonical way to sort arbitrary data. For instance should
[1, 2, 3] come before or after [1, 3, 2]? Should [1] come before or
after [[1]]? Is there some structure to your data, or can it be any
values? Are all your strings made of digits, and should they be
compared as numbers (ie should '10' come after '2'?)

If you can say how to compare two of your data, say by defining a
compare function
def cmp(a, b):

Then you can sort your list using sorted(my_list, cmp=cmp).

Without knowing what your data means, and what you're planning to do
with it, it's not possible for anyone to answer your question

Paul Hankin

Oct 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
by: markus | last post by:
I usually store info in arrays using field names $array='Germany', $array="GE"; $array='United Sates" $array="US"; $array='France" $array='FR"
by: Gaspard Kayitare | last post by:
I would like to know how to use multidimensional arrays principles for sorting grades for four students obtained in four subjects.I am supposed to arrange the data in a form of a table,students names by rows and subjects/course units by columns.How should I organise my c++ code.The program should sort the grades of each students in ascending...
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int...
by: Joshua Russell | last post by:
Hi, I wish to parse an XML file into some sort or array or multidimensional storage. The XML file is as follows (without any parent tags just to give you an idea of the structure)... <Ship Name="Disrupter" Class="CC" PrimaryTarget="CR" BattleOrder="1" Guns="5" Power="2"></Ship> <Ship Name="Zealot" Class="CR" PrimaryTarget="CC" BattleOrder="2"...
by: Henrik | last post by:
im reciving an error when i tries to read multidimensional XML data, into my system. I'm receving the same errors discriped at: http://support.microsoft.com/default.aspx?scid=kb;en-us;325695 And http://support.microsoft.com/kb/325696/EN-US/ But I can't find a solution for the problem???
by: Rehceb Rotkiv | last post by:
Hello everyone, can I sort a multidimensional array in Python by multiple sort keys? A litte code sample would be nice! Thx, Rehceb
by: glbdev | last post by:
I have a multidimensional array with 5 keys. I need to perform a alpha sort on the 3rd key. Does anyone have an example on how to do this? Here is an example of what my array consists of: mArray(i,0) = '2007-05-02" mArray(i,1) = "6:00pm" mArray(i,2) = "TEXT TEXT TEXT" <------------------ NEED TO DO ALPHA SORT ON THIS KEY...
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize function: x = new int;
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.