Re: longest sequence
by Bengt Richter other posts by this author
Feb 17 2003 10:19PM messages near this date
Re: Arrays Vs. Lists
|
The value of ACE in Black Jack
On Mon, 17 Feb 2003 11:44:11 -0600, "Mark McEahern" <mark@[...].com> wrote:
> 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?
>
> >> def longest(seq): return reduce(max, map(len, seq))
...
> >> aSeq = '1111', '222'
> >> longest(aSeq)
4
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
|