重拾python 二十五
来源:互联网 发布:天下无人不通共 知乎 编辑:程序博客网 时间:2024/05/01 21:59
继续总结:
#!/usr/bin/python # -*- coding: utf-8 -*-def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef 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 print wordsdef print_last_word(words): """Prints the last word after popping it off.""" word = words.pop(-1) print word print wordsdef 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)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)sentence = "4This 3is 1my 5test 2word."print_first_and_last(sentence)print_first_and_last_sorted(sentence)
运行:
python ex25.py
有:
4This['3is', '1my', '5test', '2word.']2word.['3is', '1my', '5test']1my['2word.', '3is', '4This', '5test']5test['2word.', '3is', '4This']
0 0
- 重拾python 二十五
- 重拾Python 二
- 重拾python 二十
- 重拾python 二十一
- 重拾python 二十二
- 重拾python 二十四
- 重拾python 二十六
- 重拾python 二十七
- 重拾python 二十八
- 重拾python 二十九
- python入门(二十五):反射
- Python进阶(二十五)-Python读写文件
- python 学习笔记(二十五)
- python入门(二十五):logging模块
- 二十五
- Python的学习(二十五)-- os.path模块
- python第三方库系列之二十五--pip库
- 【Python学习系列二十五】数据结构-有向图绘制
- 类的继承与派生、多态、this指针、函数模板与类模板
- 735 A. Ostap and Grasshopper codeforces
- electron开发记录(二):VisualStudioCode相关
- 初窥wireshark fiddler等抓包工具及部分实现分析
- 【caffe配置】SSD(Single Shot MultiBox Detector)在Windows下配置步骤
- 重拾python 二十五
- python爬取防爬虫网站的数据
- 735 B. Urbanization codeforces
- 只用一个div画一个太极图
- 编码:隐匿在计算机软硬件背后的语言(3)--二进制加法器
- 我自己的小介绍
- sizeof与strlen
- iptables配置——NAT地址转换
- 关于Oracle数据库IO等待相关指标的较为系统的分析方法