The best way to check if two lists have identical values

mk mrkafk at gmail.com
Thu Feb 25 09:43:53 EST 2010


On 2010-02-25 14:55, Arnaud Delobelle wrote:

> Your code checks if the two lists have the same length and the same
> elements, but not necessarily the same number of each elements. E.g.
>
>      qips = [1, 1, 2]
>      oldqips = [1, 2, 2]
>
> will return True
>
> If you want to check if each value has the same number of occurences,
> you can do
>
>      return sorted(qips) == sorted(oldqips)
>
> assuming that all elements in the lists are comparable.

Thanks!

Regards,
mk




More information about the Python-list mailing list