What\'s the easiest way to check if a string only contains certain specified characters in Python? (Without using RegEx or anything, of course)
Specifically, I have
Assuming the discrepancy in your example is a typo, then this should work:
my_list = ['aba', 'acba', 'caz']
result = [s for s in my_list if not s.strip('abc')]
results in ['aba', 'acba']
. string.strip(characters) will return an empty string if the string to be stripped contains nothing but characters in the input. Order of the characters should not matter.