Check if list contains only item x
If all items in the list are hashable:
set(A) == set([x])
This checks that all element
s in A
are equal to x
without reference to any other variables:
all(element==x for element in A)
A=[w,y,x,z]
all(p == x for p in A)
That, or if you don't want to deal with a loop:
>>> a = [w,x,y,z]
>>> a.count(x) == len(a) and a
(and a
is added to check against empty list)