473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Multidimensional sort

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

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

Oct 10 '07 #1
1 1135
On Oct 10, 8:47 pm, termiflyer <dpfl...@earthlink.netwrote:
How do I sort this:
>a

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

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

[['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
properly.

--
Paul Hankin

Oct 10 '07 #2

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

Similar topics

1
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',
2
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"
1
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...
9
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...
11
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...
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...
16
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
2
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: ...
9
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.