Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialcheyenne hemmati
1,195 PointsWord_count question
I have gone thru this many times comparing correct answers but can someone explain to me what: dictionary[word] = string.lower().split().count(word)
is doing please. The = part is throwing me off.
def word_count(string): dictionary = {} for word in string.lower().split(): dictionary[word] = string.lower().split().count(word) return dictionary
def word_count(string):
dictionary = {}
for word in string.lower().split():
dictionary[word] = string.lower().split().count(word)
return dictionary
1 Answer
Steven Parker
231,269 PointsThe key is the term in the brackets, in this case the contents of "word".
The value is what is being assigned, so it is whatever the expression on the right side of the equal sign evaluates to.
cheyenne hemmati
1,195 Pointsomg thank you so much!
cheyenne hemmati
1,195 Pointscheyenne hemmati
1,195 Pointsso its adding the word to the dictionary, but how does the key and the value get identified.