Pythonic way to determine if one char of many in a string
Nicolas.Dandrimont at crans.org
Mon Feb 16 13:09:28 EST 2009
* python at bdurham.com <python at bdurham.com> [2009-02-16 00:48:34 -0500]:
> > 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
If you want to put this in its own function, this seems to be the way to go.
The nice thing about Windows is - It does not just crash, it displays a
dialog box and lets you press 'OK' first.
(Arno Schaefer's .sig)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 204 bytes
Desc: Digital signature
More information about the Python-list