Could someone help me fix my this code?

Can someone explain to be line 6, why it is not indented.

The purpose of the code is to see the number of appearance of a same letter of a word. For example the word “apple” will print {apple:2} because the mode letter is p and it is appeared in the word twice. However, I do not fully understand the code from 4 to 6(especially 6).

Thank you

def frequency_dictionary(words):
  freqs = {}
  for word in words:
    if word not in freqs:
      freqs[word] = 0
    freqs[word] += 1
  return freqs

  #print(frequency_dictionary(["apple", "apple", "cat", 1]))
# should print {"apple":2, "cat":1, 1:1}

Could someone help me fix my this code?

We doubt this is your code, so won’t be giving any help. Go back and review the unit on dictionaries to get back up to speed. When you get back to this exercise, write your own code and you’ll know what it means and what it does.

Rule One of Coding: Don’t use code you could not have written yourself, especially if you don’t understand how it works and what it does.

What is there to fix, do you reason?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.