How to check all elements of a list are same or different

John Posner jjposner at snet.net
Wed Apr 15 19:54:53 EDT 2009


Scott David Daniels wrote:
> Assuming you really are going for "is" comparison, how about:
>     max(id(x) for x in mylist) == min(id(x) for x in mylist)
>
> It has the advantage that if [id(x) for x in mylist] = [2N, 1N, 3N],
> you get the answer you desire.
>
Oops -- got me!  -John



More information about the Python-list mailing list