Skip to content

Instantly share code, notes, and snippets.

@SeanPlusPlus
Created November 17, 2015 00:56
Show Gist options
  • Save SeanPlusPlus/8004d5184d6335bf9533 to your computer and use it in GitHub Desktop.
Save SeanPlusPlus/8004d5184d6335bf9533 to your computer and use it in GitHub Desktop.
#!/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