compare_two_lists.py

#!/usr/bin/python3
# ===================================================================
# from: www.digital.ocean/com/community/tutorials/
#       how-to-compare-two-lists-in-python
# ===================================================================
#
# Methods to Compare Two Lists in Python
#
#    The reduce() and map() function.
#    The collection. counter() function.
#    Python sort() function along with == operator.
#    Python set() function along with == operator.
#    The difference() function.
#
# ===================================================================

import functools

l1 = [ 10,20,30,40 ]

l2 = [ 10,20,30,40 ]

l3 = [ 20,30,40,10 ]

l4 = [ 10,20,30,40,50 ]

if functools.reduce(lambda x, y : x and y, \
             map(lambda p,q : p == q,l1,l2), True):
    print('l1 matches l2')
else:
    print('l1 does not match l2')

if functools.reduce(lambda x, y : x and y, \
             map(lambda p,q : p == q,l1,l3), True):
    print('l1 matches l3')
else:
    print('l1 does not match l3')