Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dict.get() example needs clarification #31

Open
Akuli opened this issue Jun 25, 2021 · 1 comment
Open

dict.get() example needs clarification #31

Akuli opened this issue Jun 25, 2021 · 1 comment

Comments

@Akuli
Copy link
Owner

Akuli commented Jun 25, 2021

<Arrinao> sentence = input("Enter a sentence: ")
<Arrinao> counts = {}
<Arrinao> for word in sentence.split():
<Arrinao>     counts[word] = counts.get(word, 0) + 1
<Akuli> two cases: word is not in counts, word is in counts
<Akuli> word not in counts:   counts[word] = 0+1
<Akuli> s o when we see it for the first time, set count to 1
<Akuli> and when word is in counts, it does:   counts[word] = counts[word] + 1
<Akuli> so when we see a word we already saw before, we increment the count
@Anas-debug
Copy link

Anas-debug commented Jan 3, 2022

@Akuli
I get it this is some kind of histogram.
I'll take this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants