Advertisement
gauravssnl

break_sort_word_sentence.py

Oct 28th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # break,sort words & sentences
  2.  
  3. def break_words(stuff):
  4.     return  stuff.split(" ")
  5.  
  6. def sort_words(words):
  7.      words.sort()
  8.      return words    
  9.  
  10. def print_first_word(words):
  11.     word = words.pop(0)
  12.     print word
  13.  
  14. def print_last_word(words):
  15.     word = words.pop(-1)
  16.     print word
  17.  
  18. def sort_sentence(sentence):
  19.     words = break_words(sentence)
  20.     return sort_words(words)
  21.  
  22. def print_first_and_last(sentence):
  23.     words = break_words(sentence)
  24.     print_first_word(words)
  25.     print_last_word(words)
  26.  
  27. def print_first_and_last_sorted(sentence):
  28.     words = sort_sentence(sentence)
  29.     print_first_word(words)
  30.     print_last_word(words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement