Last active
October 22, 2015 07:39
-
-
Save RachellCalhoun/8fb170031853803923b9 to your computer and use it in GitHub Desktop.
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
def most_common_letter(string): | |
common = dict() | |
letters = list() | |
for letter in string: | |
letters.append(letter) | |
for x in letters: | |
common[x] = common.get(x,0) + 1 | |
maxkey = None | |
maxval = None | |
for key,val in common.items(): | |
if val > maxval: | |
maxkey = key | |
maxval = val | |
return maxkey, maxval | |
# These are tests to check that your code is working. After writing | |
# your solution, they should all print true. | |
print('most_common_letter("abca") == ["a", 2]: ' + str(most_common_letter('abca') == ['a', 2])) | |
print('most_common_letter("abbab") == ["b", 3]: ' + str(most_common_letter('abbab') == ['b', 3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment