Frequency using Counter

Run Settings
LanguagePython
Language Version
Run Command
from collections import Counter #### FREQUENCY OF STRING #### msg = "Hello" freq_msg = Counter(msg) print(freq_msg) # Counter({'l': 2, 'H': 1, 'e': 1, 'o': 1}) print("Frequencies are: ") for key, value in freq_msg.items(): print(key, value) # Frequencies are: # H 1 # e 1 # l 2 # o 1 #### FREQUENCY OF LIST #### my_list = [11, 5, 10, 11, 11, 5, 10, 5, 5] freq_my_list = Counter(my_list) print(freq_my_list) # Counter({5: 4, 11: 3, 10: 2}) print("Frequencies are: ") for key, value in freq_my_list.items(): print(key, value) # Frequencies are: # 11 3 # 5 4 # 10 2
Editor Settings
Theme
Key bindings
Full width
Lines