Check if two list of tuples are identical in Python

PythonServer Side ProgrammingProgramming

When it is required to check if two list of tuples are identical, the '==' operator is used.

The '==' operator checks to see if two iterables are equal or not.

A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).

A list of tuple basically contains tuples enclosed in a list.

Below is a demonstration of the same −

Example

Live Demo

my_list_1 = [(11, 14), (54, 58)]
my_list_2 = [(98, 0), (10, 13)]

print("The first list of tuple is : ")
print(my_list_1)
print("The second list of tuple is : ")
print(my_list_2)

my_result = my_list_1 == my_list_2

print("Are the list of tuples identical?")
print(my_result)

Output

The first list of tuple is :
[(11, 14), (54, 58)]
The second list of tuple is :
[(98, 0), (10, 13)]
Are the list of tuples identical?
False

Explanation

  • Two list of tuples are defined, and are displayed on the console.
  • The tuples are checked for being identical using the '==' operator.
  • This is assigned to a value.
  • It is displayed on the console.
raja
Published on 12-Mar-2021 05:45:37
Advertisements