我是靠谱客的博主 迷人帽子,最近开发中收集的这篇文章主要介绍Coursera Chaptereight:Lists Assignment 8.4,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 athttp://www.pythonlearn.com/code/romeo.txt




fname = raw_input("Enter file name: ")


fh = open(fname)
lst = list()
for line in fh:
    line=line.rstrip()
    a=line.split()
    lst.append(a)
    l2=list()
for i in range(len(lst)):
    l2=l2+lst[i]
l2=list(set(l2))
l2.sort()
print l2


最后

以上就是迷人帽子为你收集整理的Coursera Chaptereight:Lists Assignment 8.4的全部内容,希望文章能够帮你解决Coursera Chaptereight:Lists Assignment 8.4所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部