Created
November 17, 2015 00:56
-
-
Save SeanPlusPlus/8004d5184d6335bf9533 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
#!/usr/bin/env python | |
import collections | |
def main(): | |
di = {} | |
f = file('in.txt', 'r') | |
for line in f: | |
k = line.rstrip().split(',')[0] | |
v = line.rstrip().split(',')[1] | |
try: | |
di[k].append(v) | |
except KeyError: | |
di[k] = [v] | |
f = file('out.txt', 'w') | |
od = collections.OrderedDict(sorted(di.items())) | |
for k, v in od.items(): | |
#print k, v | |
s = k + ',' | |
for el in v: | |
s += el + ';' | |
if s[-1] == ';': | |
s = s[:-1] | |
s += '\n' | |
f.write(s) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment