Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program with count the number of occurrences of each substring in a word
- # and display them in descending order
- from collections import Counter
- def consecutive_groups(iterable):
- s = tuple(iterable)
- for size in range(1, len(s) + 1):
- for index in range(len(s) + 1 - size):
- yield iterable[index:index+size]
- userInput = raw_input("Please enter a word or * when done: ")
- substring_list = []
- while (userInput != "*"):
- substring_list = substring_list + list(consecutive_groups(userInput))
- userInput = raw_input("Please enter a word or * when done: ")
- substring_count = Counter(substring_list)
- substring_descending_order = substring_count.most_common()
- print substring_descending_order
Advertisement
Add Comment
Please, Sign In to add comment