From the course: Go for Python Developers

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Maps

Maps

- [Instructor] Let's talk about Maps, not these kind of maps. So here we'd like to calculate what is the most common word in Rumi's poem. So we define the poem, it's a multi-line string so we use triple quotes and then we define the frequency as an empty dictionary. And then for every word in poem.split we say the frequency of the word is the frequency.get of word and zero, in case we encounter the word for the first time, +1. And then for the most common, we use the built in max function, giving it the frequency and say that you compare words by looking at the frequency.get, meaning the count of the word, and finally, print out the most common one. Let's run this, so run without debugging and we see those in the terminal. Let me close this one and let's move in to the go one. So here we define the poem. For multi line strings we use back tick in go, this is known as a raw string in go. We define frequency and the…

Contents