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

Chris Rebert clp2 at rebertia.com
Wed Apr 15 17:49:28 EDT 2009


On Wed, Apr 15, 2009 at 2:36 PM, Gaurav Moghe <moghegau at msu.edu> wrote:
> Hi,
>
> I am an amateur python user I wanted to know how do I know whether all the
> contents of a list are all same or all different? Now, I could certainly
> write a loop with a counter. But is there a ready command for that? Checked
> a lot of docs and this mailing list, but didnt get anything worthwhile.
> Would be glad to know.

All same:

list_1 == list_2

All different:

all(x != y for x, y in zip(list_1, list_2))

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list