- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if tuple and list are identical in Python
When it is required to check if a tuple and a list are identical, i.e they contain same elements, a simple loop can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
Below is a demonstration of the same −
my_tuple_1 = ('Hi' , 'there', 'Will') my_list = ['How' ,'are' ,'you'] print("The tuple is : ") print(my_tuple_1) print("The list is : ") print(my_list) my_result = True for i in range(0, len(my_list)): if(my_list[i] != my_tuple_1[i]): my_result = False break print("Are the tuple and list identical ? ") print(my_result)
The tuple is : ('Hi', 'there', 'Will') The list is : ['How', 'are', 'you'] Are the tuple and list identical ? False
- A tuple and a list are defined and displayed on the console.
- A variable is assigned the 'True' value.
- The list is iterated over, and every element from the list and the tuple are compared.
- If they are not same, the variable that was previously assigned 'True' is assigned a 'False' value.
- It breaks out of the loop.
- The final result is the Boolean value stored in the variable.
- It is displayed on the console
- Python - Check if all elements in a list are identical
- Check if two list of tuples are identical in Python
- Check if two lists are identical in Python
- Python – Check if any list element is present in Tuple
- Python Program to check if two given matrices are identical
- Check if variable is tuple in Python
- C# program to check if two matrices are identical
- Program to check if two given matrices are identical in C++
- Check if element is present in tuple in Python
- Java program to check if two given matrices are identical
- Check if tuple has any None value in Python
- Check if two Tuple Objects are equal in C#
- Python - Check if all elements in a List are same
- Why are there separate tuple and list data types in Python?
- Python program to check whether two lists are circularly identical