Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active November 11, 2018 00:08
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 toyeiei/2498944a9b3214780c565a31a425b849 to your computer and use it in GitHub Desktop.
Save toyeiei/2498944a9b3214780c565a31a425b849 to your computer and use it in GitHub Desktop.
Python tutorial - write simple function to count item in a list
# write a reusable function
def count_item(input_list):
"""count item in a list, return a dict"""
result = {}
for item in input_list:
if item in result:
result[item] += 1
else:
result[item] = 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment