Created
March 8, 2022 09:20
-
-
Save QuintD/cc45545c5aa04be2bca5ecb38e60d632 to your computer and use it in GitHub Desktop.
Shows how you can use dictionary data structure in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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