Skip to content

Instantly share code, notes, and snippets.

@fabiosoft
Created October 17, 2019 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiosoft/a5e4e0bf59bbab1eee768d6d00ff3dc6 to your computer and use it in GitHub Desktop.
Save fabiosoft/a5e4e0bf59bbab1eee768d6d00ff3dc6 to your computer and use it in GitHub Desktop.
Array list diffing in python
# Python program to find the missing
# and additional elements
# source: https://www.geeksforgeeks.org/python-find-missing-additional-values-two-lists/
# examples of lists
list1 = [1, 2, 3, 4, 5, 6]
list2 = [4, 5, 6, 7, 8]
# prints the missing and additional elements in list2
print("Missing values in second list:", (set(list1).difference(list2)))
print("Additional values in second list:", (set(list2).difference(list1)))
# prints the missing and additional elements in list1
print("Missing values in first list:", (set(list2).difference(list1)))
print("Additional values in first list:", (set(list1).difference(list2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment