Program - Given a list iterate it and count the occurrence of each element and create a dictionary to show the count of each elemen


Topic: Program - Given a list iterate it and count the occurrence of each element and create a dictionary to show the count of each elemen

Solution

sampleList = [11, 45, 8, 11, 23, 45, 23, 45, 89]
countDict = dict()
for item in sampleList:
  if(item in countDict):
    countDict[item] += 1
  else:
    countDict[item] = 1
  
print("Printing count of each item  ",countDict)



List all Python Programs