On Oct 10, 8:47 pm, termiflyer <[EMAIL PROTECTED]> wrote:
> 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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to