Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Created December 8, 2015 20:05
Show Gist options
  • Save NotTheEconomist/4ff165a4a6318f435ee3 to your computer and use it in GitHub Desktop.
Save NotTheEconomist/4ff165a4a6318f435ee3 to your computer and use it in GitHub Desktop.
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