471,310 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 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 1080
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brian | last post: by
1 post views Thread by Gaspard Kayitare | last post: by
9 posts views Thread by Charles Banas | last post: by
11 posts views Thread by Joshua Russell | last post: by
16 posts views Thread by Rehceb Rotkiv | last post: by
reply views Thread by rosydwin | last post: by

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.