Wilbert Berendsen <wbs...@xs4all.nl> wrote:

> # sort the keys, longest first, so 'aa' gets matched before 'a', because
> # in Python regexps the first match (going from left to right) in a
> # |-separated group is taken
> keys = sorted(mapping.keys(), key=len, reverse=True)
> 

This would do just as well (although see Iain King's response for the 
correct answer):

keys = sorted(mapping, reverse=True)

You don't need to specify key=len because the default sorting for two 
strings where one is a prefix of the other will always sort them that way 
anyway, and you don't need to call mapping.keys() because that's what 
sorted will sort anyway.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to