Created
December 8, 2015 20:05
-
-
Save NotTheEconomist/4ff165a4a6318f435ee3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open("file2.txt") as b: | |
reader = csv.reader(b, delimiter="|") | |
ranges = {range(int(start), int(end)): [three, four] for start, end, three, four, *_ in reader} | |
with open("file1.txt") as a, \ | |
open("file3.txt", 'wb') as outf: | |
writer = csv.writer(outf, delimiter="|") | |
for line in a: | |
n = int(line.strip()) | |
for r, val in ranges.items(): | |
if n in r: | |
writer.writerow([n] + val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment