Skip to content

Instantly share code, notes, and snippets.

@rainzoo
Created January 26, 2013 16:01
Show Gist options
  • Save rainzoo/4643028 to your computer and use it in GitHub Desktop.
Save rainzoo/4643028 to your computer and use it in GitHub Desktop.
Extract unique combinations of columns (number 1 to 4) in a tab separated file.
with open('sample.txt') as fi:
dct = {}
header = fi.readline()
"""Couldn't figure what this row is for
"""
rec1 = fi.readline()
for line in fi.readlines():
x = line.split()[1:5]
key = ",".join(x)
dct[key] = dct.get(key, 0) + 1
with open('out.txt','w') as fout:
for k in dct.keys():
fout.write(k.replace(",","\t"))
fout.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment