Program to find the given element in list using Python

by | Jan 25, 2021 | Python Programs


In this section, we will understand the python code to find whether the element is in the list or not. Python provides ‘in’ keyword to easily find the element in the list.

Program to find the given element in list


list = ['is', 'st', 'around', 'in', 'the']
element = input("Enter the preposition to find: ")
# Check if it exists in list
if (element in list):
    print("Element Exists!")
    print("Element does not exists!")



Program to find the given element in list Output


In the above python code, we have created a variable element which takes the user input. Through ‘in’ statement the variable element is checked against each value in list and if the searched value exists in the list the output “Element exists!” is displayed on the screen otherwise “Element does not exists!” is displayed.

The other way to find the element in the list is by converting the list into set first and then applying ‘in’ to the set. The disadvantage of using set() + in is that the duplicate value will get removed.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.