Python script to identify regex matches in all subdirs and write dict of matches to MongoDB
f.readlines() is redundant. Just iterate over the file: for i, line in enumerate(f):, or, as you are not using i at all: for line in f: 
d.setdefault becomes redundant if you use d = collections.defaultdict(list)