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?
Sort, then compare.
sorted(a) == sorted(b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With