可爱的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- ...
随机推荐
- 常用shell命令中你所不熟悉的参数
1. ls: 类似于dos下的dir命令 ls最常用的参数有三个: -a -l -F. ls –a Linux上的文件以.开头的文件被系统视为隐藏文件,仅用ls命令是看不到他们的,而用ls -a除 ...
- [JAVA]HTTP请求应答作输入输出
请求(需要发送数据给别人): URL url = new URL("需要请求的URL连接"); HttpURLConnection httpConnection = (HttpUR ...
- ibatis.net 中SqlMaps的xml文件的例子
<?xml version="1.0" encoding="utf-8" ?> <!--=========================== ...
- NOIP2009分数线划定【B004】
[B004]分数线划定[难度B]—————————————————————————————————————————————————————————————————————————— [题目要求] 世博 ...
- ASP.NET Cache缓存的用法
本文导读:在.NET运用中经常用到缓存(Cache)对象.有HttpContext.Current.Cache以及HttpRuntime.Cache,HttpRuntime.Cache是应用程序级别的 ...
- [资料分享]Python视频教程(基础篇、进阶篇、项目篇)
Python是一种开放源代码的脚本编程语言,这种脚本语言特别强调开发速度和代码的清晰程度.它可以用来开发各种程序,从简单的脚本任务到复杂的.面向对象的应用程序都有大显身手的地方.Python还被当作一 ...
- 对于amqplib的使用心得
最近在nodejs使用了amqplib--rabbitmq的nodejs客户端.封装在了express中,先来代码. var amqp = require('amqplib/callback_api' ...
- Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken
在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...
- 榮耀6 Plus將是一部沒有對手的手機
華為榮耀官方微博發佈消息正式確定了年度旗艦新品將命名為榮耀6 Plus,據稱,該機將是“2014年度最最旗艦手機”,並將集“科學與美學一身”.“探索幾何與視覺極限”,同時,官方微博還不低調地宣稱該機將 ...
- delphi URL 编码的转换
先介绍一下,Delphi中处理Google的URL编码解码,其中就会明白URL编码转换的方法的 从delphi的角度看Google(谷歌)URL编码解码方式 在网上搜索了一下,似乎没有什么关于goog ...