Are all characters in a string in the set?

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.

+3
source share
1 answer
>>> set("aeiou").issuperset("hello world")
False
>>> set("aeiou").issuperset("eoo")
True
+5
source

All Articles