0

I just don't understand why we using square brackets on dict[char]

Letter Counter Given a string as input, you need to output how many times each letter appears in the string. You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values. Create a program to take a string as input and output a dictionary, which represents the letter count. answer: text = input() dict = {} for char in text: dict[char] = text.count(char) print(dict)

8th Dec 2021, 4:05 PM
Chen qian
Chen qian - avatar
1 Respuesta
+ 4
With the square brackets, we we access the value of the key: dict[key] = value You may want to review the lesson about dictionnaires in the sololearn Python course
8th Dec 2021, 4:18 PM
Lisa
Lisa - avatar