Python Question

How can I compare two lists in python, and return that the second need to have the same values regardless of order?

a = [1, 2, 3, 4]
b = [2, 4, 3, 1]
c = [2, 3]


When comparing a to b, should return
True
: all items in
a
are presented in
b
, and all items in
b
are presented in
a
.

When comparing
a
to
c
, should return
False
: there are items in
a
that don't exist on
c
.

What is the pythonic way to do it?

Answer

Sort, then compare.

sorted(a) == sorted(b)