Aldarion <[EMAIL PROTECTED]> writes:
> how to sorted by summed itemgetter(1)?
> maybe sorted(items,key = lambda x:sum(x[1]))
> can't itemgetter be used here?

You really want function composition, e.g.

    sorted(items, key=sum*itemgetter(1))

where * is a composition operator (doesn't exist in Python).

You could write:

   def compose(f,g):
      return lambda *a,**k: f(g(*a,**k))

and then use

   sorted(items, key=compose(sum,itemgetter(1)))

or spell it out inline:

   sorted(items, key=lambda x: sum(itemgetter(1)(x)))

I'd probably do something like:

   snd = itemgetter(1)    # I use this all the time
   sorted(items, key=lambda x: sum(snd(x)))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to