4

Bag of Words

Unsolved
NLP

Difficulty: 2 | Problem written by zeyad_omar
Problem reported in interviews at

Amazon
Facebook
Google

Bag of Words is a representation for sentences containing a dictionary of words and their corresponding number of occurences.

In this problem, you are given a sentence and asked to return a dictionary containing the number of occurences of each word in the sentence. The keys are each word, and the values are the count of the word.

 

Sample Input:
<class 'list'>
sentence: ['to', 'be', 'Pro', 'in', 'ML', 'you', 'need', 'MLPro']

Expected Output:
<class 'dict'>
{'to': 1, 'be': 1, 'Pro': 1, 'in': 1, 'ML': 1, 'you': 1, 'need': 1, 'MLPro': 1}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Iusto odio suscipit quo esse doloribus sed minima omnis qui accusantium, inventore ullam possimus, corporis laborum consequuntur eligendi recusandae dolorem, quaerat placeat nemo, distinctio ducimus voluptate iusto sint libero. Totam eum doloribus nihil vitae id accusantium dolorem velit, mollitia dicta veritatis minus voluptatibus deleniti, facilis optio voluptas ex corrupti laboriosam quia unde ullam expedita excepturi sunt, saepe provident quidem fugit beatae molestiae sit itaque. Maxime suscipit quae debitis tempore?

Maxime velit vel alias, pariatur ea obcaecati vero fugit explicabo animi facilis maxime quasi ab porro.

Consectetur modi ipsum officiis ullam, labore eveniet facere? Doloremque quaerat possimus rem, aliquam minus at non temporibus ullam unde deserunt odit, cum quae id explicabo consequuntur vel esse perferendis placeat accusantium dignissimos dolor, voluptas omnis ad accusamus quasi aut repudiandae deleniti optio quisquam error?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)