ezoic

Wednesday, February 22, 2017

is_member function

Write a function 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 aFalse 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']))

Results:







1 comment:

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...