reviewing ex.15 to 26
This commit is contained in:
parent
402d63519d
commit
d270952bf0
6 changed files with 59 additions and 22 deletions
36
sami/learn-python-the-hard-way/ex25.py
Normal file
36
sami/learn-python-the-hard-way/ex25.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
def break_words(stuff):
|
||||
"""This function will break up words for us."""
|
||||
words = stuff.split(' ')
|
||||
return words
|
||||
|
||||
|
||||
def sort_words(words):
|
||||
"""Sorts the words."""
|
||||
return sorted(words)
|
||||
|
||||
|
||||
def print_first_word(words):
|
||||
"""Prints the first word after popping it off."""
|
||||
word = words.pop(0)
|
||||
print(word)
|
||||
|
||||
|
||||
def print_last_word(words):
|
||||
"""Prints the last word after popping it off."""
|
||||
word = words.pop(-1)
|
||||
print(word)
|
||||
|
||||
|
||||
def sort_sentence(sentence):
|
||||
"""Takes in a full sentence and returns the sorted words."""
|
||||
words = break_words(sentence)
|
||||
return sort_words(words)
|
||||
|
||||
|
||||
def print_first_and_last(sentence):
|
||||
"""Prints the first and last words of the sentence."""
|
||||
words = break_words(sentence)
|
||||
print_first_word(words)
|
||||
print_last_word(words)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue