可爱的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中分割字符串
java.lang.String 的 split() 方法, JDK 1.4 or later public String[] split(String regex,int limit) 示例代码 p ...
- Microchip微芯HCS301解密HCS360解密HCS361芯片解密多少钱?
Microchip微芯HCS系列芯片解密型号: HCS101 | HCS200 | HCS201 | HCS201T | HCS300 | HCS300T HCS301 | HCS301T | HCS ...
- 分享Kali Linux 2016.2第50周虚拟机
分享Kali Linux 2016.2第50周虚拟机该虚拟机使用Kali Linux 2016.2第50周的64位镜像安装而成.基本配置如下:(1)该系统默认设置单CPU双核,内存为2GB,硬盘为50 ...
- Django学习笔记之二
一.使用Django自带的后端管理平台 1.后台创建管理员 python manage.py createsuperuser Email address: admin@example.com Pass ...
- 2016 Multi-University Training Contest 2
8/13 2016 Multi-University Training Contest 2官方题解 数学 A Acperience(CYD)题意: 给定一个向量,求他减去一个 α(>=0)乘以 ...
- JQuery上传插件Uploadify使用详解
本文转载http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html Uploadify是JQuery的一个上传插件,实现的效果非常不错 ...
- Leetcode Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...
- Object-C 1.0 第二章
1. 输出obc #import <Foundation/Foundation.h> int main(int argc,const char *argv[]) { NSLog(@&qu ...
- About_Return
返回值:return return 表示从被调函数返回到主调函数继续执行,返回时可附带一个返回值,由return后面的参数指定. return通常是必要的,因为函数调用的时候计算结果通常是通过返回值带 ...
- Codeforces Round #371 (Div. 2) C
传送门 map或者字典数的应用 简单题 题意: 思路: AC代码: #include<iostream> #include<cstring> #include<cmat ...