[Tutor] 2 problems in a small script
Dick Moores
rdm at rcblue.com
Fri Oct 12 13:39:56 CEST 2007
At 03:41 AM 10/12/2007, Kent Johnson wrote:
>Aditya Lal wrote:
>>finalList = [ word for word in lstA if wellformed(word) ]
>
>or do everything in one statement:
> finalList = [ word for word in lstA if all(c in astr for c in word) ]
I'm just not comfortable with list comprehensions yet, but I see that
although yours is very succinct, it's clear enough. And I'd forgotten
about the all() and any() (both new with 2.5
<http://docs.python.org/lib/built-in-funcs.html>.)
>Note to Dick:
>You don't have to convert word to a list before iterating it:
> wordWithCommas = list(word)
> print "wordWithCommas is", wordWithCommas
> for char in wordWithCommas:
>
>could be just
> for char in word:
Sure, strings are iterable. Dumb of me.
Thanks,
Dick
More information about the Tutor
mailing list