Skip to content

Instantly share code, notes, and snippets.

@alghanmi
Created January 20, 2014 18:25
Show Gist options
  • Select an option

  • Save alghanmi/8525937 to your computer and use it in GitHub Desktop.

Select an option

Save alghanmi/8525937 to your computer and use it in GitHub Desktop.
List Diff - A Doff Tool for Lists. Perform a diff between a pair of lists.
"""List Diff - A Doff Tool for Lists
Perform a diff between a pair of lists.
Usage:
listdiff.py <file1> <file2>
listdiff.py -h | --help
listdiff.py --version
Arguments:
<file1> the file containing the first list
<file2> the file containing the second list
Options:
-h --help Show this screen
--version Show version
"""
from docopt import docopt
def print_list(mylist):
'''Print a list, one element per line and indented by a tab'''
for i in mylist:
print '\t{}'.format(i)
if __name__ == '__main__':
args = docopt(__doc__, version='List Diff v1.0')
list1 = [ ]
with open(args['<file1>'], 'r') as f1:
list1 = [line.strip() for line in f1]
list2 = [ ]
with open(args['<file2>'], 'r') as f2:
list2 = [line.strip() for line in f2]
inL1notL2 = list(set(list1) - set(list2))
inL2notL1 = list(set(list2) - set(list1))
print 'In {}, but not in {}'.format(args['<file1>'], args['<file2>'])
print_list(inL1notL2)
print ''
print 'In {}, but not in {}'.format(args['<file2>'], args['<file1>'])
print_list(inL2notL1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment