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