0

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?

cycla
  • 147
  • 5

1 Answers1

1
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}
B. Bogart
  • 998
  • 6
  • 15