Skip to content

Instantly share code, notes, and snippets.

@crizCraig
Created April 17, 2012 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crizCraig/2408259 to your computer and use it in GitHub Desktop.
Save crizCraig/2408259 to your computer and use it in GitHub Desktop.
synonyms = {'scotty': 'dog', 'puppy': 'dog', 'dog': 'dog'}
counts = [(2, 'dog'), (2, 'puppy'), (2, 'scotty')]
syn_counts = []
for count in counts:
syn_counts.append((count[0], synonyms[count[1]]))
print syn_counts
sum_counts = {}
for syn_count in syn_counts:
try:
sum_counts[syn_count[1]] += syn_count[0]
except:
sum_counts[syn_count[1]] = syn_count[0]
print sum_counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment