ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved