[Baypiggies] list sorting

Alex Martelli aleax at google.com
Thu Jun 24 21:59:12 CEST 2010


>>> import operator
>>> sorted(z1, key=operator.itemgetter(2,0,1))
[[34, 44, '1011'], [40, 20, '1011'], [40, 60, '1011'], [10, 30, '1013'],
[50, 50, '1013']]
>>>


Alex

On Thu, Jun 24, 2010 at 12:46 PM, Vikram <kpguy at rediffmail.com> wrote:

> Suppose i have this:
> ------
>
> >>> z1 =
> [[34,44,'1011'],[40,60,'1011'],[50,50,'1013'],[40,20,'1011'],[10,30,'1013']]
> >>> z1
> [[34, 44, '1011'], [40, 60, '1011'], [50, 50, '1013'], [40, 20, '1011'],
> [10, 30, '1013']]
> >>> for i in z1:
> print i
>
>
> [34, 44, '1011']
> [40, 60, '1011']
> [50, 50, '1013']
> [40, 20, '1011']
> [10, 30, '1013']
> >>>
>
> ----
>
> how do i sort the nested list z1 so as to obtain:
>
> bla =
> [[34,44,'1011'],[40,20,'1011'],[40,60,'1011'],[10,30,'1013'],[50,50,'1013']]
>
>
>
> <http://sigads.rediff.com/RealMedia/ads/click_nx.ads/www.rediffmail.com/signatureline.htm@Middle?>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100624/da168b66/attachment.html>


More information about the Baypiggies mailing list