【Python】Learn Python the hard way, ex25 函数综合练习
2015-10-11 19:33
796 查看
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): """Print 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 second words.""" words = break_words(sentence) return sort_words(words) def print_first_and_last(sentence): """Print the first and last words of the sentence.""" words = break_words(sentence) print_first_word(words) print_last_word(words) 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)
导入模块前,需要在Eclipse中配置添加其路径,否则无法识别
相关文章推荐
- python.time
- python中魔法属性和魔法方法
- Python魔法方法指南
- 【Python】Learn Python the hard way, ex24 函数综合练习
- leetcode之Largest Number
- PYTHON getattr setattr hasattr delattr内置函数
- 【Python】Learn Python the hard way, ex21 函数返回值return
- python 将中文转拼音后填充到url做参数并写入excel
- Python格式化输出
- Python格式化输出
- 【Python】Learn Python the hard way, ex20 用函数读文件readline
- 关于python测试webservice接口的视频分享
- 关于python测试webservice接口的视频分享
- 关于python测试webservice接口的视频分享
- 【Python】Learn Python the hard way, ex19 函数和变量
- 将 Sublime 3 打造成 Python/Django IDE
- 【Python】:如何安装及编译python程序
- python stock 1
- 【Python】Learn Python the hard way, ex18 def函数
- python编译器IDLE的问题。