[portland] Sorting A List of Tuples

kirby urner kirby.urner at gmail.com
Thu Nov 8 18:55:14 CET 2007


Again, the 'key' argument helps get around the need for DSU in many cases:

>>> seq = [
    ['a', 1, 5],
    ['b', 3, 4],
    ['c', 2, 2],
    ['d', 4, 3],
    ['e', 5, 1],
]
>>> seq.sort(key=lambda x: x[2])
>>> seq
[['e', 5, 1], ['c', 2, 2], ['d', 4, 3], ['b', 3, 4], ['a', 1, 5]]

Kirby


On Nov 8, 2007 9:51 AM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Thu, 8 Nov 2007, Dylan Reinhardt wrote:
>
> > Try DSU:
> >
> > http://www.goldb.org/goldblog/CommentView,guid,6969f8b8-5710-4b4c-ad7a-0f545da805da.aspx
>
>    How cool!
>
> > HTH
>
>    Yes, it does, Dylan.
>
> Thanks very much,
>
>
> Rich
>
> --
> Richard B. Shepard, Ph.D.               |  Integrity            Credibility
> Applied Ecosystem Services, Inc.        |            Innovation
> <http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863
> _______________________________________________
> Portland mailing list
> Portland at python.org
> http://mail.python.org/mailman/listinfo/portland
>


More information about the Portland mailing list