0
def lookup(content):
    value=True
    if any(x not in content for x in ['A','B','C']):
        value = False
    print (value)

What i want is check if any of these 'A' 'B' 'C' is in a string , for example if string equates ABCAA then the value will be true, if the string is ABDC then value is wrong because content contains a char not defined in my list above.The issue is i'm getting false with that function for 'ABC' which isn't supposed to happen.

Alex
  • 3
  • 2

2 Answers2

1

Just use sets:

# input
my_string = 'abcd'

# set of allowed characters
approved_characters = set('abc')

# characters in string that are not in set of approved characters
unapproved_characters = set(my_string) - approved_characters # gives {'d'}
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
0

Try this:

def lookup(content):
    print(all(x in ['A','B','C'] for x in content))

lookup('ABC') #output: True
gommb
  • 1,121
  • 1
  • 7
  • 21