scattered <tooscatte...@gmail.com> writes:
> def invert(p):
>       return [ j for (i,j) in sorted(zip(p,range(len(p))))]


   return [j for i,j in sorted(enumerate(p), key=itemgetter(1))]

looks a little cleaner to me.

    In Haskell or ML, you can use patterns that contain wild
    cards that play a role in the pattern-matching but don't establish any
    binding. Can that be done in Python?

Not as much.  You could say something like

         sorted(enumerate(p), key=lambda(_,j): j)

which gets the meaning across (it binds the symbol "_" though this
doesn't escape the lambda).
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to