Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Testing if two lists are equal regardless of the order of the objects in it

Is there a way to check if two lists are equal, depending on the values in it but regardless of their order.

for example:

[3,4,5] == [5,3,4] will be: true

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can of course sort the 2 lists and then compare them, the question is whether it is possible to check if lists are equal using their values, without sorting them

>Solution :

You can use Counter from collections

Counter(listA) == Counter(listB)

or if you want to sort them

sorted(listA) == sorted(listB)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading