# Python – Check if any list element is present in Tuple

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

When it is required to check if any list element is present in a tuple or not, a Boolean value and a simple iteration are used.

Below is a demonstration of the same −

## Example

Live Demo

my_tuple = (14, 35, 27, 99, 23, 89,11)

print("The tuple is :")
print(my_tuple)

my_list = [16, 27, 88, 99]

print("The list is :")
print(my_list)

my_result = False

for element in my_list:
if element in my_tuple :
my_result = True
break

print("The result is :")
if(my_result == True):
print("The element is present in the tuple")
else:
print("The element isn't present in the tuple")

## Output

The tuple is :
(14, 35, 27, 99, 23, 89, 11)
The list is :
[16, 27, 88, 99]
The result is :
The element is present in the tuple

## Explanation

• A tuple of integers is defined and is displayed on the console.

• A list of integers is defined and is displayed on the console.

• A Boolean value is assigned to ‘False’ initially.

• The list is iterated over, and if the element in the tuple is present in the list, the Boolean value is reinitialized to ‘True’.

• The control breaks out of the loop.

• Depending on the value of Boolean variable, the output is displayed on the console.

Updated on 04-Sep-2021 10:44:01