Possible Duplicate:
check if all elements in a list are identical
I want to check if all of the elements of a list are equal. I couldn’t do this with:
if all (x == x for x in (a, b, c, d)):
...
Is there very minimalistic and elegant way to do this in Python?
If you have only hashable elements in your list you can use a set.
For example if your list is named
lstyou can do:The set will eliminate all the duplicates in your list, so if the length of the set is 1 it means that all the elements are the same.