Lostsoul Lostsoul - 1 month ago 10
Python Question

Is there a way to see if two lists are the exact same without looping in python?

Say I have:

a = [1, 2, 3]
b = [1, 2, 3]


is there a way to test the lists to see if they are the same, without having to loop through each entry?

Here's what I was thinking..I know to check if two variables are the same I could use:

id(a)


but it doesn't work because the ID's are different so is there some type of checksum or way that python stores values of the table so I can simply compare two variables?

Answer

Doesn't == work?

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a == b
True