brewersfan1976

ch4-ex1.py

Jul 31st, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. # a program that takes input from the user and only prints out words that begin with a vowel and
  2. # prints them in alphabetical order and in descending order based on their frequency
  3.  
  4. from collections import Counter
  5. import re
  6.  
  7. userInput = raw_input("Please enter a sentence: ")
  8. list = []
  9.  
  10. for w in userInput.split():
  11.     if (w.startswith("a")):
  12.        list.append(w)
  13.  
  14.     if (w.startswith("e")):
  15.        list.append(w)
  16.  
  17.     if (w.startswith("i")):
  18.        list.append(w)
  19.  
  20.     if (w.startswith("o")):
  21.        list.append(w)
  22.  
  23.     if (w.startswith("u")):
  24.        list.append(w)
  25.  
  26.     if (w.startswith("A")):
  27.        list.append(w)
  28.  
  29.     if (w.startswith("E")):
  30.        list.append(w)
  31.  
  32.     if (w.startswith("I")):
  33.        list.append(w)
  34.  
  35.     if (w.startswith("O")):
  36.        list.append(w)
  37.  
  38.     if (w.startswith("U")):
  39.        list.append(w)
  40.  
  41. # print the list in Alphabetical order
  42.  
  43. list.sort()
  44.  
  45. print "We will now print the list in Alphabetical order"
  46. print
  47. print list
  48. print
  49. print "We will now print the list in descending order of frequency"
  50. print
  51.  
  52. words = Counter(list)
  53.  
  54. print words
Advertisement
Add Comment
Please, Sign In to add comment