Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # program that breaks a string into characters and stores them in dictionary
- # also stores the number of each characters in a string and displays them in descending order
- from collections import Counter
- # get input from user
- userInput = raw_input("Please enter a sentence: ")
- # break the string into separate characters and store them in a list
- characters = list(userInput)
- # count the number of each character in the string
- character_count = Counter(characters)
- # store the number of characters in descending order
- character_count_descending = character_count.most_common()
- # create a dictionary
- d = {}
- # store the list in a dictionary
- d = dict(character_count)
- print d
- # print sorted dictionary
- print character_count_descending
Advertisement
Add Comment
Please, Sign In to add comment