Re: [Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Kent Johnson
Andreas Kostyrka wrote: > With 2.5 you can even do stuff like that: > x=[range(5), range(3), range(7)] max(x, key=lambda i: len(i)) > [0, 1, 2, 3, 4, 5, 6] No need for the lambda, just use max(x, key=len) Kent ___ Tutor maillist - Tutor@py

Re: [Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Tony Cappellini
Thanks, but I am restricted to using 2.3.4 for now, so longest = max([len(x) for x in ll]) works for me On 12/28/06, Andreas Kostyrka <[EMAIL PROTECTED]> wrote: * Python <[EMAIL PROTECTED]> [061228 20:44]: > On Thu, 2006-12-28 at 11:27 -0800, Tony Cappellini wrote: > > > > > > I want to use

Re: [Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Andreas Kostyrka
* Python <[EMAIL PROTECTED]> [061228 20:44]: > On Thu, 2006-12-28 at 11:27 -0800, Tony Cappellini wrote: > > > > > > I want to use a list comp to get the length of the longest string in a > > list, but can't quite get the syntax right. > > > > l1=['abc', 'abcde', 'abcfdtea'] > > > > longest=0 >

Re: [Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Python
On Thu, 2006-12-28 at 11:27 -0800, Tony Cappellini wrote: > > > I want to use a list comp to get the length of the longest string in a > list, but can't quite get the syntax right. > > l1=['abc', 'abcde', 'abcfdtea'] > > longest=0 > [x for x in l1 if len(x) > longest] Use max to get the longe

[Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Tony Cappellini
I want to use a list comp to get the length of the longest string in a list, but can't quite get the syntax right. l1=['abc', 'abcde', 'abcfdtea'] longest=0 [x for x in l1 if len(x) > longest] The problem is I can't add the true clause to the if statement in a list comp as in if len(x) > longes