Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active Nov 11, 2018
Embed
What would you like to do?
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