Alex Rivera | Logout

all list values same

Asked 2011-01-20T20:37:31.257
24

In Python, is the a simple way to test that all values in a list are equal to one another?

Edit
Report

1 Answer

13
>>> a = [1, 1, 1, 1]
>>> len(set(a))
1

Note that this method assumes that each element in your list can be placed into a set. Some types, such as the mutable types, cannot be placed into a set.

answered 2011-01-20T20:41:11.333

Your Answer