Is there an easy way to determine if all characters in a string belong to a given character set? I have the following loop code, which I feel can be shortened:
def allInSet(mystr, myset):
result = True
for char in mystr:
result &= (char in myset)
return result
Examples:
>>> allInSet("yyyow", set(['a','e','i','o','u','w','y']))
True
>>> allInSet("yowza", set(['a','e','i','o','u','w','y']))
False
list(mystr) in set(['a','b','c']) did not work.
source
share