How to efficiently compare two unordered lists (not sets) in Python?

前端 未结 10 1115
刺人心
刺人心 2020-11-22 15:00
a = [1, 2, 3, 1, 2, 3]
b = [3, 2, 1, 3, 2, 1]

a & b should be considered equal, because they have exactly the same elements, only in different

10条回答
  •  余生分开走
    2020-11-22 15:48

    Using the unittest module gives you a clean and standard approach.

    import unittest
    
    test_object = unittest.TestCase()
    test_object.assertCountEqual(a, b)
    

提交回复
热议问题