
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Check if any list element is present in Tuple
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
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.
- Related Articles
- Check if element is present in tuple in Python
- Check if element is present in tuple of tuples in Python
- Check if tuple has any None value in Python
- Check if tuple and list are identical in Python
- Python – Test if tuple list has a single element
- How do you check if an element is present in a list in Java?
- Check if variable is tuple in Python
- Maximum element in tuple list in Python
- Python - Check if two lists have any element in common
- Remove tuple from list of tuples if not containing any character in Python
- Update each element in tuple list in Python
- Check if element exists in list of lists in Python
- Check if elements of Linked List are present in pair in Python
- Python Program to Test if any set element exists in List
- Python Check if suffix matches with any string in given list?

Advertisements