<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1" />
    <title>Pythonic way to determine if one char of many in a string</title>
  </head>
  <body dir="ltr">
    I need to test strings to determine if one of a list of chars is in the string. A simple example would be to test strings to determine if they have a vowel (aeiouAEIOU) present.<br /><br />I was hopeful that there was a built-in method that operated similar to startswith where I could pass a tuple of chars to be tested, but I could not find such a method.<br /><br />Which of the following techniques is most Pythonic or are there better ways to perform this type of match?<br /><br /># long and hard coded but short circuits as soon as match found<br />if 'a' in word or 'e' in word or 'i' in word or 'u' in word or ... :<br /><br />-OR- <br /><br /># flexible, but no short circuit on first match<br />if [ char for char in word if char in 'aeiouAEIOU' ]:<br /><br />-OR-<br /><br /># flexible, but no short circuit on first match<br />if set( word ).intersection( 'aeiouAEIOU' ):<br /><br />Thank you,<br />Malcolm<br />

  </body>
</html>