Coursera:Python for Everybody Specialization
刚开始准备转码刷题,先入门一门语言python,跟的是Coursera上PYTHON FOR EVERYBODY 的专项课,目标是基本掌握语言可以简单抓包,在刷题的时候改Java格式完成刷题。
这个系列的课还是很容易上手的,for everybody嘛,一共有5门课程:
-
1 Programming for Everybody (Getting Started with Python)
-
2 Python Data Structure
-
3 Using Python to Access Web Data
-
4 Using Databases with Python(+SQL)
-
5 Capstone: Retrieving, Processing, and Visualizing Data with 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 the split() method. 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.
You can download the sample data at http://www.py4e.com/code3/romeo.txt
#fname = input("Enter file name: ")
##fh = open(fname)
##sum = list()
##for line in fh:
## line=line.rstrip()
## line=line.split()
## sum=sum+line
##for i in range(len(sum)-1):
## #print(i)
## j=i+1
## while j<len(sum)-1:
## #print(j)
## if sum[i]==sum[j]:
## #print(sum[i])
##
## sum.remove(sum[i])