码迷,mamicode.com
首页 > 其他好文 > 详细

ex25.py

时间:2016-11-23 07:04:00      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:opp   last   color   return   cti   pop   this   turn   function   

 1 def break_words(stuff):
 2     """This is function will break up words for us."""
 3     words = stuff.split( )
 4     return words
 5 
 6 def sort_words(words):
 7     """sort the words."""
 8     return sorted(words)    
 9 
10 def print_frist_word(words):
11     """prints the frist word after popping it off."""
12     word = words.pop(0)
13     print (word)
14 
15 def print_last_word(words):
16     """Prints the last word after popping it off"""
17     word = words.pop(-1)
18     print (word)
19 
20 def sort_sentence(sentence):
21     """Take in a full sentence and returns the sorted words."""
22     words = break_words(sentence)
23     return sort_words(words)
24     
25 def print_frist_and_last(sentence):
26    """prints the frist and last word of the sentence."""
27    words = break_words(sentence)
28    print_frist_word(words)
29    print_last_word(words)
30 
31 def print_frist_and_last_sorted(sentence):
32     """Sorts the words then prints the frist and last one."""
33     words = sort_sentence(sentence)
34     print_frist_word(words)
35     print_last_word(words)

 

ex25.py

标签:opp   last   color   return   cti   pop   this   turn   function   

原文地址:http://www.cnblogs.com/jiangzhipeng/p/6092167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!