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:

R is not a simple programming language, and it does better on reading excel files than python

R is not a simple programming language, and it does better on reading excel files than python . tried to read excel files to python and R. i...