How to convert list into dictionary

cycla

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?

B. Bogart
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.

edited at
0

Comments

0 comments
Login to comment

Related