- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
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")
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
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.
- 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
- How do you check if an element is present in a list in Java?
- Check if variable is tuple in Python
- Check if tuple and list are identical in Python
- Python - Check if two lists have any element in common
- Python – Test if tuple list has a single element
- Check if elements of Linked List are present in pair in Python
- Remove tuple from list of tuples if not containing any character in Python
- Python Check if suffix matches with any string in given list?
- Maximum element in tuple list in Python
- Check if substring present in string in Python
- Check if one tuple is subset of other in Python
- Check if element exists in list of lists in Python