[Tutor] list comprehensions
Sean 'Shaleh' Perry
shalehperry@attbi.com
Wed, 21 Aug 2002 08:28:57 -0700
On Wednesday 21 August 2002 02:05 am, Gregor Lingl wrote:
> >given that list each item will end up in the return. You really need =
to
> > loop twice. Once to find the longest word then again to find those t=
hat
> > are at least as big. Or did I misunderstand your comment? For insta=
nce
> > given my example list above the return list would simply be:
> >
> >['z' * 26]
>
> I disagree:
> >>> tl
>
> ['a', 'bb', 'ccc', 'dddd', 'eeeee']
>
> >>> filterLongest(tl)
>
> ['eeeee']
>
> >>> filterLongest(tl*4)
>
> ['eeeee', 'eeeee', 'eeeee', 'eeeee']
>
>
> imho this is what is intended. In the above code l collects all the
> words having
> length of the longest word encountered so far. If a longer word occurs
> l is replaced by a new list containing only this one which then may be
> appended to.
>
You are correct. I would be wary of the performance but there is no bug =
as I=20
asserted earlier.