Advertisement
pleabargain

python 3 the hard way exe 25

May 4th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #http://learnpythonthehardway.org/book/ex25.html
  2. #very powerful stuff... the code runs but I think there are some issues with python 2.7 and 3.3 here.
  3. #not sure
  4. #need to investigate
  5.  
  6. def break_words(stuff):
  7.     """This function will break up words for us"""
  8.     words =stuff.split(' ')
  9.     return words
  10.  
  11. def sort_words(words):
  12.     """sort the words"""
  13.     return sorted(words)
  14.  
  15. def print_first_word(words):
  16.     """print the first word after popping it off"""
  17.     words =words.pop(0)
  18.     print ("word")
  19.  
  20. def print_last_word(words):
  21.     """ Prints the last word after popping it off"""
  22.     words = words.pop(-1)
  23.     print ("word")
  24.  
  25.  
  26. def sort_sentence(sentence):
  27.     """Prints the first and last words of the sentence. """
  28.     words = break_words(sentence)
  29.     print_first_word(words)
  30.     print_last_word(words)
  31.  
  32. def print_first_and_last_sorted(sentence):
  33.     """Sorts the words then prints the first and last one. """
  34.     words = sort_sentence(sentence)
  35.     print_first_word(words)
  36.     print_last_word(words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement