Pythonic way to determine if one char of many in a string
python at bdurham.com
python at bdurham.com
Mon Feb 16 00:48:34 EST 2009
Nicolas,
> I would go for something like:
>
> for char in word:
> if char in 'aeiouAEIUO':
> char_found = True
> break
> else:
> char_found = False
>
> It is clear (imo), and it is seems to be the intended idiom for a
> search loop, that short-circuits as soon as a match is found.
Thank you - that looks much better that my overly complicated attempts.
Are there any reasons why I couldn't simplify your approach as follows?
for char in word:
if char in 'aeiouAEIUO':
return True
return False
Cheers,
Malcolm
More information about the Python-list
mailing list