Last active
June 13, 2016 20:33
-
-
Save GISmd/e9dcc8a9805cafc7c762ad9e91714145 to your computer and use it in GitHub Desktop.
Finding missing elements between two lists using collections module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
def findmissing(expectedlist, foundlist): | |
"""Compare two lists and output lists of items that are not included""" | |
expected = collections.Counter(expectedlist) | |
found = collections.Counter(foundlist) | |
not_in_found = list((found - expected).elements()) | |
not_in_expected = list((expected - found).elements()) | |
return not_in_expected, not_in_found | |
#%% Example Usage: | |
expectedlist = ['1','2','3'] | |
foundlist = ['2','3','4'] | |
not_in_expected, not_in_found = findmissing(expectedlist, foundlist) | |
print not_in_found | |
print not_in_expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment