Created
January 26, 2013 16:01
-
-
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.
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
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