I want to find the count of strings in the given array
example if I give an input [the ,the ,the]
the output : {‘the’ : 3}
And I came up with solution below,which is working ,but I could’nt understand the commented line in the code.When we add a string with a number it returns typeError.
Then how is this working.
chr_ = 'the the the'
dit_ = {}
def count_characters(chr_ ='the the power power power nikhil nikhil'):
count = 1
list_ = chr_.split()
for i in list_:
if not i in dit_:
dit_[i] = count
else:
dit_[i] += count # how does this line help us?
return
count_characters()
print(dit_)