-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_ex25.py
34 lines (28 loc) · 839 Bytes
/
py_ex25.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def breakWords(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
def sortWords(words):
"""Sort the words."""
return sorted(words)
def printFirstWord(words):
word = words.pop(0)
print word
def printLastWord(words):
"""Prints the last word after popping it off."""
word = words.pop(-1)
print word
def sortSentence(sentence):
"""Takes in a full sentence and eturns the sirted words."""
words = breakWords(sentence)
return sortWords(words)
def printFirstAndLast(sentence):
"""Prints the first and last words of the sentence."""
words = breakWords(sentence)
printFirstWord(words)
printLastWord(words)
def printFirstAndLastSorted(sentence):
"""Sorts the words then prints first and last one."""
words = sortSentence(sentence)
printFirstWord(words)
printLastWord(words)