Introduction To Python - Learn Python the hard way v2.0
Title: Exercise 25
# Defination to split the words in the sentence
def break_words(stuff):
    """This function will break up words for us."""
    words = stuff.split(' ')
    return words

# Def to sort the words in the list
def sort_words(words):
    """Sorts the words."""
    return sorted(words)

#Def to print fistr element from the list
def print_first_word(words):
    """Prints the first word after popping it off."""
    word = words.pop(0)
    print word

#def to print last element from the 
def print_last_word(words):
    """Prints the last word after popping it off."""
    word = words.pop(-1)
    print word

#def to sort the sentence.It calls the function break_words and sort_words
def sort_sentence(sentence):
    """Takes in a full sentence and returns the sorted words."""
    words = break_words(sentence)
    return sort_words(words)

#def to print the lasta nd first word from the sentence.
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)


#def to print the lasta nd first word from the sorted sentence.
def print_first_and_last_sorted(sentence):
    """Sorts the words then prints the first and last one."""
    words = sort_sentence(sentence)
    print_first_word(words)
    print_last_word(words)

-----------OUTPUT------------
harshada@hsangale-Ub-in:~/harshada/work/python/assignment$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ex25
>>> sentence = "Introduction To Python Learn Python the hard way"
>>> words = ex25.break_words(sentence)
>>> words
['Introduction', 'To', 'Python', 'Learn', 'Python', 'the', 'hard', 'way']
>>> sort_words = ex25.sort_words(words)
>>> sort_words
['Introduction', 'Learn', 'Python', 'Python', 'To', 'hard', 'the', 'way']
>>> first_word = ex25.print_first_word(words)
Introduction
>>> last_word = ex25.print_last_word(words)
way
>>> sort_sent = ex25.sort_sentence(sentence)
>>> sort_sent
['Introduction', 'Learn', 'Python', 'Python', 'To', 'hard', 'the', 'way']
>>> print ex25.print_first_and_last(sentence)
Introduction
way
None
>>> a = ex25.print_first_and_last(sentence)
Introduction
way
>>> a = ex25.print_first_and_last_sorted(sentence)
Introduction
way