Use max() to choose longest match

Theoretically this is more efficient than using sorted().