[Tutor] Re: list comprehensions

Prahlad Vaidyanathan slime@vsnl.net
Wed, 21 Aug 2002 11:14:05 +0530


Hi,

On Tue, 20 Aug 2002 Tim Wilson spewed into the ether:
> Hi everyone,
> 
> I'm wondering if it's possible to implement the following function using
> list comprehensions. It's not really a speed issue because it runs in a
> split second using the built-in dictionary on my Linux box.

Well, if speed is not an issue, this should work :

"""
def filterLongest(words) :
    maxlen = max([len(word) for word in words])
    return [ w for w in words if len(w) == maxlen ]
"""

    HTH,

pv.
-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

There will be big changes for you but you will be happy.