Python Data Structure: Compare two unordered lists
Python Data Structure: Exercise-11 with Solution
Write a Python program to compare two unordered lists (not sets).
Sample Solution:
Python Code :
from collections import Counter
def compare_lists(x, y):
return Counter(x) == Counter(y)
n1 = [20, 10, 30, 10, 20, 30]
n2 = [30, 20, 10, 30, 20, 50]
print(compare_lists(n1, n2))
Sample Output:
False
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to group a sequence of key-value pairs into a dictionary of lists.
Next: Write a Python program to create an array contains six integers. Also print all the members of the array.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/data-structures-and-algorithms/python-data-structure-exercise-11.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics