So I’m trying to find an item in a list in python. Here is my function:
def operator(input):
operatorlist = ['+', '-', '*', '/', '^', 'sin', 'cos']
for i in operatorlist:
if input is operatorlist[i]:
return True
My code is breaking, and I can’t figure out why… any ideas?
I changed my code from:
def operator(input):
if input is '+' or input is '-' or input is '*' or input is '/' or input is '^' or input is 'sin' or input is 'cos':
return True
Because I was told that is was, essentially, stylistically dumb to write it that way.
One line :
No need to do conditions here, the in operator already returns a boolean.