dgadiraju
12/17/2017 - 6:13 AM

CountBySocial.py

import itertools as it, sys
from itertools import chain

def getCountBySocial(srkrData):
  srkrDataMap = chain. \
    from_iterable(it.imap(lambda s: s.split("\t")[7].split(", "), srkrData))
  srkrGroupby = it.groupby(sorted(srkrDataMap))
  srkrGroupbyMap = it.imap(lambda t: (t[0], len(list(t[1]))), srkrGroupby)
  return srkrGroupbyMap

srkrData = open(sys.argv[1]).read().splitlines()
for i in getCountBySocial(srkrData): print(i)