Skip to content

Instantly share code, notes, and snippets.

@rca
Created November 29, 2012 00:41
Show Gist options
  • Save rca/4165888 to your computer and use it in GitHub Desktop.
Save rca/4165888 to your computer and use it in GitHub Desktop.
Count the number of times an item appears in a list
counts = {}
for item in items:
counts.setdefault(item, 0)
counts[item] += 1
print counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment