Pergunta de entrevista da empresa Sony

Is there any other way for the above question without using any package?

Resposta da entrevista

Sigiloso

8 de jul. de 2021

Extract the words from the corpus by splitting the string using the method str. split(' '). We'll get a list containing all the words. Then declare a dictionary data structure and start a for loop to iterate over each word. In the loop, we use the error handling method. In try condition we try to add +1 to the value of the keyword, if there is no such word in a dictionary, it throws an error, taking us to except condition where we map the keyword to value 1. Instead of using the error handling method, we can use the if-else method, where we try to find whether the key is in a dictionary or not, if it is we increment the value by 1, else we map the key with value 1.

1