# beforeafter.py -- enumerate ``before and afters'' -- timdoug, 2010-11-19 # e.g., Young Doctors In Love Potion No. 9 # # list of movies from: # http://itasoftware.com/careers/work-at-ita/PuzzleFiles/movies3.txt import collections count = 0 db = collections.defaultdict(list) with open('movies3.txt') as f: for movie in f.readlines(): split_movie = movie[:-2].title().split(' ') db[split_movie[0]].append(split_movie) for movies in sorted(db.itervalues()): for movie in movies: if movie[-1] in db: print ' '.join(movie), '|', for x in sorted(db[movie[-1]]): print '(%s)' % ' '.join(x), count += 1 print print '=========\n%d before and afters found.' % count