Saturday, January 28, 2017

Searching value in a List

Tags

Question::

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.

Code::
def is_member(d,n):
    for i in n:
        if(d==i):
            return True
    return False 
n=input("Enter list:")
nt=n.split(",")    
d=input("Enter Value to be searched:")
if(is_member(d,nt)):
    print("Yes it is Present")
else:

    print("No it is not Present")


Output::