DEV Community

Discussion on: Whiteboarding in Python: Can You Solve This Simple String Problem?

Collapse
 
codemouse92 profile image
Jason C. McDonald

Another approach, throwing out the "no other data structures" rule, is to strip the string down to letters-only, convert to a set, and compare lengths:

def unique_only(s):
    s = ''.join(c.lower() for c in s if c.isalpha())
    return len(set(s)) == len(s)

unique_only("My and his bot")  # True
unique_only("These are some words")  # False
Enter fullscreen mode Exit fullscreen mode