best way to compare contents of 2 lists?

Esmail ebonak at
Fri Apr 24 12:44:18 CEST 2009

Piet van Oostrum wrote:
>>>>>> John Yeung <gallium.arsenide at> (JY) wrote:
>> JY> It takes care of the duplicates, but so does your initial solution,
>> JY> which I like best:
>>>> sorted(a)==sorted(b)
>> JY> This is concise, clear, and in my opinion, the most Pythonic.  It may
>> JY> well even be the fastest.  (If you didn't have to match up the numbers
>> JY> of duplicates, the set solution would be most Pythonic and probably
>> JY> fastest.)
> But it may fail if the list cannot be sorted because it contains
> incomparable elements:

Ah .. good point .. something I had not considered. Lucky for me in
this case it's not an issue, but something I'll keep in mind for the

More information about the Python-list mailing list