longest sequence

Mark McEahern mark at mceahern.com
Mon Feb 17 12:44:11 EST 2003


How do you detetermine the longest sequence?  Naive use of max doesn't work
(for this):

  >>> max('1111', '222')
  '222'

so I came up with this:

  def longest(*args):
      sorted = list(args)
      sorted.sort(lambda x, y: cmp(len(x), len(y)))
      return sorted[-1]

Comments?

Thanks,

// m

-






More information about the Python-list mailing list