Skip to content

Instantly share code, notes, and snippets.

@QuintD
Created March 8, 2022 09:20
Show Gist options
  • Select an option

  • Save QuintD/cc45545c5aa04be2bca5ecb38e60d632 to your computer and use it in GitHub Desktop.

Select an option

Save QuintD/cc45545c5aa04be2bca5ecb38e60d632 to your computer and use it in GitHub Desktop.
Shows how you can use dictionary data structure in Python.
# to check for the number of occurrence of each items in a list, here is the way to go.
list = [2, 2, 3, 5, 5, 7, 7, 0, 2, 3, 1, 0, 5]
dic = {}
for x in list:
if x in dic:
count = dic[x]
else:
count = 0
dic[x] = count + 1
for key, value in dic.items():
print(key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment