I'm a beginner at Python and have tried to find an explanation for this but was unsuccessful.
Currently learning how to write a for loop to count occurrences of letters in a string (sentence) and returning the results in a dictionary. I'm following an online example.
This was the example:
message = "It was a bright cold day in April, and the birds were chirping."
count = {}
for character in message.upper():
count.setdefault(character, 0)
count[character] = count[character] + 1
print(count)
I understand everything about it except
count[character] = count[character] + 1
As far as I can see, the count() function is normally formatted as:
string.count("XYZ")
I think I understand why () brackets aren't used here, because
count(character) = count(character) + 1
doesn't make much sense, but I don't understand what
count[character]
is supposed to be doing - is it creating a list of each letter in the string and iterating through it? Is it creating/referencing an index?
Thank you!