python_exercises/thinkcspy/Chapter-12-Exercises/Problem1.py

33 lines
644 B
Python
Raw Normal View History

2023-11-19 23:03:43 -07:00
# Runestone.Academy thinkcspy course
# Chapter 12
# Problem 1
2023-11-19 20:45:18 -07:00
def countAll(text):
wordDict = {}
text = text.lower()
for char in text:
if char not in wordDict and char.isalpha():
wordDict[char] = text.count(char)
return wordDict
def sortList(text):
wordDict = countAll(text)
alphaList = list(wordDict.items())
alphaList.sort()
return alphaList
def printResult(text):
alphaList = sortList(text)
print("You inputed: " + text)
for char in alphaList:
print(char[0] + ": " + str(char[1]))
printResult(input("What word(s) would you like sorted?"))