As advised by andy e while answering this question, it's not good for your script's performance if it's repeatedly building. If so, how should i then do it? If it already has a count for a given character, get.
Meghan Trainor Songs Ranked Return of Rock
11 here is my solution. Sorted will iterate through the iterable it's passed. As you have found, get just gets the value corresponding to a given key.
The get/set pattern provides a structure that allows logic to be added during the setting ('set') or retrieval ('get') of a property instance of an instantiated.
The sample code in your question is clearly trying to count the number of occurrences of each character: