Skip to content

Instantly share code, notes, and snippets.

@Turux
Last active January 27, 2021 09:18
Show Gist options
  • Save Turux/69132ee8b1d32f58e9977b0ab444b20b to your computer and use it in GitHub Desktop.
Save Turux/69132ee8b1d32f58e9977b0ab444b20b to your computer and use it in GitHub Desktop.
Summary of a Python list
# @Brief: A function that takes a python list and returns a Dict of a summary of entries and thier number of occurrences
# @Param: input_list -> Any list of elements
# @Return: result -> A Dict containig as many keys as the unique elements of input_list
# The value for each key is the number of occurance of each unique element
def summary(input_list):
result=dict()
keys=list(set(input_list))
for key in keys:
result[key]=input_list.count(key)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment