Pythonic way to determine if one char of many in a string

Stefaan Himpe stefaan.himpe at gmail.com
Mon Feb 16 14:44:55 EST 2009


An entirely different approach would be to use a regular expression:

import re
if re.search("[abc]", "nothing expekted"):
    print "a, b or c occurs in the string 'nothing expekted'"

if re.search("[abc]", "something expected"):
    print "a, b or c occurs in the string 'something expected'"

Best regards,
Stefaan.



More information about the Python-list mailing list