-
-
Save codecademydev/2f61e791499ae2fffd50fb92ab698114 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write your count_first_letter function here: | |
def count_first_letter(names): | |
first_letters = {} | |
for key, value in names.items(): | |
if key[0] not in first_letters: | |
first_letters[key[0]] = len(value) | |
elif key[0] in first_letters: | |
first_letters[key[0]] += len(value) | |
return first_letters | |
# Uncomment these function calls to test your function: | |
print(count_first_letter({"Stark": ["Ned", "Robb", "Sansa"], "Snow" : ["Jon"], "Lannister": ["Jaime", "Cersei", "Tywin"]})) | |
# should print {"S": 4, "L": 3} | |
print(count_first_letter({"Stark": ["Ned", "Robb", "Sansa"], "Snow" : ["Jon"], "Sannister": ["Jaime", "Cersei", "Tywin"]})) | |
# should print {"S": 7} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment