Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
397 B

  1. package main
  2. import "fmt"
  3. func main() {
  4. words := map[string]int{
  5. "Gonna": 3,
  6. "You": 3,
  7. "Give": 2,
  8. "Never": 1,
  9. "Up": 4,
  10. }
  11. max_word := ""
  12. max_count := 0
  13. for word, count := range words {
  14. if count > max_count {
  15. max_word, max_count = word, count
  16. }
  17. }
  18. fmt.Println("Most popular word:", max_word)
  19. fmt.Println("With a count of:", max_count)
  20. }