I want to convert the list into dictionary where key is the integer stated in the list, and value is the frequency of number in the list. for example,
list = [10,10,10,20,20,40,50]
then the dictionary would look like,
dict = { '10': 3, '20': 2, '40': 1, '50': 1}.
What would be the method for this conversion?
nlist = [10,10,10,20,20,40,50]
ndict = {}
for item in set(nlist):
ndict[item] = nlist.count(item)
creates ndict:
{40: 1, 10: 3, 20: 2, 50: 1}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments