best way to align words?

Noah Rawlins noah.rawlins at comcast.net
Fri Dec 1 03:46:44 CET 2006


Noah Rawlins wrote:
> 
>  >>> strList = []
>  >>> strList.append('this is an example of a thing i would like to have')
>  >>> strList.append('another example of something else i would like to 
> have')
>  >>> strList.append('and this is another " example " but of something ; 
> now i would still like to have')
>  >>> [word for word in strList[0].split() if word in reduce(lambda x, y: 
> x.intersection(y), [set(str.split()) for str in strList])]
> ['example', 'of', 'i', 'would', 'like', 'to', 'have']
> 

I think that ends up doing the set reduction over and over for every 
word in the first string, so you probably want to move that outside the 
list comprehension

noah


More information about the Python-list mailing list