is_member()
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. (Note that this is exactly what the in
operator does, but for the sake of the exercise you should pretend Python did not have this operator.)Solution:
def is_member(c,l):
bool1=0
for item in l:
bool1=bool(c==item)+bool1
if bool1>0:
return('True')
else:
return('False')
if __name__=='__main__':
print(is_member('a',['c','a','a']))
javascript codes to learn
ReplyDelete