On Thu, 06 Jan 2005 15:31:22 +0100, J Berends <[EMAIL PROTECTED]> wrote:
>Suppose I have a list of dictionaries and each dict has a common keyname 
> with a (sortable) value in it.
> 
> How can I shuffle their position in the list in such way that they 
> become sorted.
> 
  In Python 2.4,

    import operator
    L.sort(key=operator.itemgetter(key))

  In Python 2.3,

    L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
    L2.sort()
    L = [d for (v, i, d) in L2]

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

Reply via email to