Hello fellow colleagues,

How did they know that, score[leter], which is included as part of the code will take the values from the dictionary

Thank you

Thank you

The variable leter is defined in the loop. When you declare a variable in a loop:

for vars in something

The code basically reads this as the variable vars now stands for everything in something which gets iterated through (characters in a string, elements in a list). In Python’s dictionaries, theses values-the values that get looped through-are the keys of the dictionary. Therefore calling:


gives the value stored in that key of the dictionary scores.
I hope this helps!

I kind of get it so to get the values generally you remember


Yes. It is very similar to when you do list indexing, except it is with the keys you make, rather than the ordered 0, 1, etc of list keys.

ok thank you that helps

1 Like

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