Skip to content

Instantly share code, notes, and snippets.

@jmoy
Created June 6, 2019 07:27
Show Gist options
  • Save jmoy/ecd9c1d10991fcf31ac81ec34076f5dc to your computer and use it in GitHub Desktop.
Save jmoy/ecd9c1d10991fcf31ac81ec34076f5dc to your computer and use it in GitHub Desktop.
Three Counters
counters = {key:collections.Counter() for key in ['child','mother','father']}
with open("day2/names.csv") as f:
rdr = csv.DictReader(f)
for r in rdr:
for key in counters:
l = r[key].split()
if len(l)>0:
counters[key][l[0]] += 1
commonize = lambda ctr,N: {t[0] for t in ctr.most_common(N)}
common = {key:commonize(ctr,10) for key,ctr in counters.items()}
common
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment