可爱的Python_课后习题_CDay−4 可用的首个Python 脚本
- 读取文件cdays−4-test.txt 内容,去除空行和注释行后,以行为单位进行排序,并将结果输出为cdays−4-result.txt。
cdays−4-test.txt的内容
#some words
Sometimes in life,
You find a special friend;
Someone who changes your life just by being part of it.
Someone who makes you laugh until you can't stop;
Someone who makes you believe that there really is good in the world.
Someone who convinces you that there really is an unlocked door just waiting
for you to open it. This is Forever Friendship.
when you're down,
and the world seems dark and empty,
Your forever friend lifts you up in spirits and makes that dark and empty
world
suddenly seem bright and full.
Your forever friend gets you through the hard times,the sad times,and the
confused times.
If you turn and walk away,
Your forever friend follows,
If you lose you way,
Your forever friend guides you and cheers you on.
Your forever friend holds your hand and tells you that everything is going
to be okay.
cdays−4-result.txt的内容
If you lose you way,
If you turn and walk away,
Someone who changes your life just by being part of it.
Someone who convinces you that there really is an unlocked door just waiting
Someone who makes you believe that there really is good in the world.
Someone who makes you laugh until you can't stop;
Sometimes in life,
This is Forever Friendship.
You find a special friend;
Your forever friend follows,
Your forever friend gets you through the hard times,the sad times,and the
Your forever friend guides you and cheers you on.
Your forever friend holds your hand and tells you that everything is going
Your forever friend lifts you up in spirits and makes that dark and empty
and the world seems dark and empty,
confused times.
for you to open it.
suddenly seem bright and full.
to be okay.when you're down,
world
python程序
#-*- coding:utf-8 -*-
import os if __name__ == "__main__": rFile = open(u"E:/cdays-4-test.txt", "r")
wFile = open(u"E:/cdays-4-result.txt", "w") lines = rFile.readlines()
newlines = list()
for line in lines:
#去掉空行和注释
if line == "\r\n" or line == "\n" or line.startswith("#"):
continue newlines.append(line) #按照行进行排序
newlines.sort()
wFile.write("%s" % "".join(newlines)) rFile.closed
wFile.closed
可爱的Python_课后习题_CDay−4 可用的首个Python 脚本的更多相关文章
- 可爱的Python_课后习题_CDay−2 完成核心功能
1. 在前文的grep 实现例子中,没有考虑子目录的处理方式,因为如果直接open 目录进行读grep 是古老实用且高效的模式文本匹配工具,在所有的Unix/Linux 系统中都会默认安装,它最常做的 ...
- 可爱的Python_课后习题_CDay−3 通过函式进行功能化
1. 读取某一简单索引文件cdays−3-test.txt,其每行格式为:文档序号关键词,现须根据这些信息将它转化为倒排索引,即统计关键词在哪些文档中,格式如下:包含该关键词的文档数关键词 => ...
- 可爱的Python_课后习题_CDay−5 Python 初体验和原始需求
计算今年是否是闰年.判断闰年条件,满足年份模400 为0,或者模4 为0 但模100不为0. def is_learp_year(year): """判断年份是否为润年& ...
- 可爱的Python_课后习题_CDay0 时刻准备着!发布
请根据软件发布的流程和软件开发的编码规范,将读者在前面章节所写的程序修改并发 布出去.另外,可以查找下除了 epydoc 外还有哪些较好的 py 文档生成器? pydoc是Python自带的模块,主要 ...
- CentOS7入门到精通实战课程课后习题
Linux自动化运维系列①: CentOS7入门到精通实战--->传送门 http://edu.51cto.com/course/13055.html 01.系统入门课后习题 1.口述一个命令执 ...
- 《python核心编》程课后习题——第三章
核心编程课后习题——第三章 3-1 由于Python是动态的,解释性的语言,对象的类型和内存都是运行时确定的,所以无需再使用之前对变量名和变量类型进行申明 3-2原因同上,Python的类型检查是在运 ...
- web实验指导书和课后习题参考答案
实验指导书 :http://course.baidu.com/view/daf55bd026fff705cc170add.html 课后习题参考答案:http://wenku.baidu.com/li ...
- 《Python核心编程》 第六章 序列 - 课后习题
课后习题 6–1.字符串.string 模块中是否有一种字符串方法或者函数可以帮我鉴定一下一个字符串是否是另一个大字符串的一部分? 答:成员关系操作符(in.not in) import string ...
- 《Python核心编程》 第五章 数字 - 课后习题
课后习题 5-1 整形. 讲讲 Python 普通整型和长整型的区别. 答:普通整型是绝大多数现代系统都能识别的. Python的长整型类型能表达的数值仅仅与你机器支持的(虚拟)内存大小有关. 5- ...
随机推荐
- java多线程编程
一.多线程的优缺点 多线程的优点: 1)资源利用率更好2)程序设计在某些情况下更简单3)程序响应更快 多线程的代价: 1)设计更复杂虽然有一些多线程应用程序比单线程的应用程序要简单,但其他的一般都更复 ...
- 我为什么喜欢用C#来做并发编程
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:就语言和运行时层面,C#做并发编程一点都不弱,缺的是生态和社区. 硅谷才女朱赟(我的家 ...
- LeetCode——Best Time to Buy and Sell Stock I (股票买卖时机问题1)
问题: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...
- js 一些容易错的点
最近在做平台相关功能,需要和js.html.以及使用bootstrap,bootstrap元素大小的设置 是比较难的. js比较容易出错的是,解析json,对象最好是使用json,这样更好解析,arr ...
- Jquery ajax 学习笔记
本人的js & jq 一直是菜鸟级别,最近不忙就看了看ajax方面的知识,文中部分内容参考自这里&这里 之前一直用js写ajax现在基于jq实现方便多了~ $.get & $. ...
- Django+Tastypie作后端,Backbone作前端的TodoMVC
TodoMVC是各种js框架入门的比较经典的例子,详细可查看github地址https://github.com/tastejs/todomvc 接着上篇文章, 1,先在github上把backbon ...
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- Unity Lightmap动态加载研究
什么情况下需要Lightmap? 移动平台上目前暂时还不能开实时光影效果,会卡成幻灯片.所以就需要将光影烘焙到贴图上. 什么情况下需要动态加载Lightmap? 1.当项目抛弃了Unity的多场景模式 ...
- 【Linux】lsof 命令,记一次端口占用查询
3月21日测试时,发现测试服务器启,总是报端口占用情况,察看端口占用情况 1-使用命令 netstat -tunlp |grep 端口号 差看下 这个端口被那个进程占用 我当前使用的 JBOSS 端口 ...
- linux设备驱动
http://blog.csdn.net/bob_fly1984/article/details/8820670 struct ov5640_data { struct ov5640_platf ...