Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # a program that takes input from the user and only prints out words that begin with a vowel and
- # prints them in alphabetical order and in descending order based on their frequency
- from collections import Counter
- import re
- userInput = raw_input("Please enter a sentence: ")
- list = []
- for w in userInput.split():
- if (w.startswith("a")):
- list.append(w)
- if (w.startswith("e")):
- list.append(w)
- if (w.startswith("i")):
- list.append(w)
- if (w.startswith("o")):
- list.append(w)
- if (w.startswith("u")):
- list.append(w)
- if (w.startswith("A")):
- list.append(w)
- if (w.startswith("E")):
- list.append(w)
- if (w.startswith("I")):
- list.append(w)
- if (w.startswith("O")):
- list.append(w)
- if (w.startswith("U")):
- list.append(w)
- # print the list in Alphabetical order
- list.sort()
- print "We will now print the list in Alphabetical order"
- print
- print list
- print
- print "We will now print the list in descending order of frequency"
- print
- words = Counter(list)
- print words
Advertisement
Add Comment
Please, Sign In to add comment