Skip to content

Instantly share code, notes, and snippets.

@Justintime50
Last active November 17, 2020 01:45
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 Justintime50/e93a639a07b45f9ffe2edbf26ad09c89 to your computer and use it in GitHub Desktop.
Save Justintime50/e93a639a07b45f9ffe2edbf26ad09c89 to your computer and use it in GitHub Desktop.
Compare Two Lists for Differences

Compare Two Lists

When you need to find a difference in large lists, simply compare their indexes one at a time and break when something doesn't match.

Usage

x = ['a', 'b', 'c']
y = ['a', 'c', 'c']

for i, z in enumerate(zip(x, y)):
  if z[0] != z[1]:
    print(f'{z} at index {i} doesn\'t match!')
    break
  else:
    print(f'Lists match at index {i}!')

Output will be:

Lists match at index 0!
('b', 'c') at index 1 doesn't match!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment