Skip to content

Instantly share code, notes, and snippets.

@GISmd
Last active June 13, 2016 20:33
Show Gist options
  • Save GISmd/e9dcc8a9805cafc7c762ad9e91714145 to your computer and use it in GitHub Desktop.
Save GISmd/e9dcc8a9805cafc7c762ad9e91714145 to your computer and use it in GitHub Desktop.
Finding missing elements between two lists using collections module
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