Element Existence in a List

Write a Python function to check if a given element exists in a list. The function should return True if the element is found, otherwise return False.

Example 1:

Input: [1,2,3,4,5], 3 
Output: True

Example 2:

Input: [1,2,3,4,5], 6 
Output: False

You can use Python’s membership operators (in, not in) to check the existence of an element in a list.

def is_element_present(lst, element):
    return element in lst

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!