Assignment 8.4 Python Data Structures

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])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值