Hello,
I've been trying to write a function that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of a, False otherwise. This is the script I could think of. I'm not even sure what might be wrong in this script! I find it tough studying Python :(
is_member(5, [5, 4, 3, 2]) returns True as expected. And every other trail also returns true! Please advise. Thanks.
def is_member(x,a):
#x = 0
a = [5, 4, 3, 2] #wrong ! always returns true!
try:
a.index(x)
return True
except:
return False