819. Most Common Word
Easy
Problem:
Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"]
Output: "ball"
Explanation: "hit" occurs 3 times, but it is a banned word. "ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. Note that words in the paragraph are not case sensitive, that punctuation is ignored (even if adjacent to words, such as "ball,"), and that "hit" isn't the answer even though it occurs more because it is banned.What to learn:
for ban in banned:
for word in result_array:
if ban.lower() == word:
result_array.remove(word)ages = {
'Matt': 30,
'Katie': 29,
'Nik': 31,
'Jack': 43,
'Alison': 32,
'Kevin': 38
}
# Return the key with the highest value in a Python dictionary.
max_value = max(ages, key=ages.get)
print(max_value)Solutions:
Counter
Defaultdict
Last updated