How to check if two unordered lists are equal in Python

2 Answers

0 votes
lst1 = [1, 2, 4, 3, 5] 
lst2 = [4, 2, 3, 5, 1] 
 
lst1.sort()
lst2.sort()

if lst1 == lst2:
   print("yes") 
else :     
   print("no")


'''
run:

yes

'''

 



answered Jan 23, 2020 by avibootz
0 votes
lst1 = [1, 2, 4, 3, 5] 
lst2 = [4, 2, 3, 5, 6] 
 
if set(lst1) == set(lst2):
   print("yes") 
else :     
   print("no")


'''
run:

no

'''

 



answered Jan 23, 2020 by avibootz

Related questions

...