words = ['rocky','mahesh','surendra','mahesh','rocky','mahesh','deepak','mahesh','mahesh','mahesh','surendra']
words_count = {}
for word in words:
words_count[word] = words_count.get(word, 0) + 1
print(words_count)
# Expected Output
# {'rocky': 2, 'mahesh': 6, 'surendra': 2, 'deepak': 1}
In this example, I just want to modify value of dict key while dict comprehension
Note: not looking other way to find occurrence/count of each key in dict.