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) > longest:
  longest = len(x)


Is this possible using a list comp?


thanks
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to