How to return false when a punctuation is present in an input

Viewed 31
# no periods, spaces or puctuation marks
punctuation_not_wanted = [".","!", " " "/"]

for punctuation_not_wanted in s:
    if punctuation_not_wanted in s:
       return false
2 Answers

You can compare them as sets. If they have same symbols, their intersection (&) will have this same symbols and will converts to True for if statement.

if set(punctuation_not_wanted) & set(s):
    return False
all([(c not in s) for c in punctuation_not_wanted])
Related