The best way to check if two lists have identical values

Daniel Stutzbach daniel at
Thu Feb 25 15:25:22 CET 2010

On Thu, Feb 25, 2010 at 7:30 AM, mk <mrkafk at> wrote:

> There's a number of complications here, depending on definition of 'lists
> with identical values', like whether the same value can be repeated
> different number of times in two lists, or whether the order of values
> matters.

Order and repetitions matter:
list1 == list2

Repetition matters, order does not:
sorted(list1) == sorted(list2) # items must be comparable

Neither matters:
set(list1) == set(list2) # items must be hashable

Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list