List开始之后就贱贱超过自己的“承受能力”了~╮(╯▽╰)╭working factory 和 everlasting memory没办法好好地转换。下面第一个栗子,一个简简单单的小memo,我居然用了一天。虽然中间上了个课。。。但还是不嗨森!!闲言少叙。开始吧~
来,上菜先:
Coursera Python 8.4
Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using thesplit() function. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in alphabetical order.
“Romeo.txt”:
NAH….大量的数据我们一般都是用”A.txt”存储的,然而如果我们想要检索其中一小部分怎么办呢?
Firstly,我们得把txt读进来啊,赋予其一个变量
B=open('A.txt')
这个地方有几点需要说明。
首先,你要找的这个txt最好是在当前目录下,即和你的python程序在同一个文件夹里边儿。但如果你说,不行,我任性,我喜欢把所有txt存在一个文件夹里面,python存在另一个文件夹里面,那么你可以添加路径,如
B=open('C:/...../,,,,,,/A.txt')
QED~
其次呢,如果说我编好一个merge_sort的程序,我的输入文件是某个含有4个整数的txt文档,但素你说不行啊,老师给的作业明明是要merge_sort十万个数啊,那你就得一步步从含有4个整数的txt到含有10个整数的txt,到20个,21个,100个,。。。然后跟别人对答案,哎,这个inversion的值是不是对了啊….你终于可以试试那个含有10万个整数的txt,还怀揣着特别激动的心情…Anyway,这里我想说明的是,如果说你同一个程序想要对N个txt进行测试。那么,接下来这个方法很常用: