Can someone explain me this:


what does this code actually do??

frequencies[word] += 1


It adds 1 to the key value for word.

Recall that we declared frequencies as a hash and set the default value of any new key to zero.

frequencies =

At this point the hash is empty so has no keys. When we insert a new key (one that does not already exist) it first gets inserted, then its default value is set, and then we increment it.

frequencies[word] += 1

Now any subsequent encounters of that same word will accumulate on that key value.


Recall that dictionaries are arbitrary collections, and like a set have no duplicate keys.


sir i am not getting into this…
for eg. this input text is : "the cow is in the table "
how this code works in this input. can u please explain sir


Please post a link to the exercise. Thanks.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.