Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Forked from isa/gist:2571012
Created May 2, 2012 13:50
Show Gist options
  • Save lost-theory/2576645 to your computer and use it in GitHub Desktop.
Save lost-theory/2576645 to your computer and use it in GitHub Desktop.
Convert in less than 30 lines
data = '''\
A, B, C
A, C, E
E, F, D
D, A, J
E, D, J'''
import itertools, collections
print "\n".join([" "+", ".join(a + (str(b),)) for (a,b) in sorted(collections.Counter(sum([list(itertools.combinations(sorted(x.strip().split(', ')), 2)) for x in data.split('\n')], [])).items(), key=lambda t: t[0])])
#output:
'''
A, B, 1
A, C, 2
A, D, 1
A, E, 1
A, J, 1
B, C, 1
C, E, 1
D, E, 2
D, F, 1
D, J, 2
E, F, 1
E, J, 1
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment