But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief
从这个文件中我必须 8.4 打开文件 romeo.txt 并逐行读取它。对于每一行,使用 split() 方法将该行拆分为单词列表。该程序应该构建一个单词列表。对于每行上的每个单词,检查该单词是否已在列表中,如果没有,则将其附加到列表中。程序完成后,按字母顺序排序并打印结果单词。您可以在http://www.py4e.com/code3/romeo.txt下载示例数据
这是框架,所以我应该只遵循这个代码,并使用append()、slpit()和sort()我应该使用它们。或者在其他情况下会显示错误。因为这个作业来自 coursera.com
fname = input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
print(line.rstrip())
输出应如下所示:
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair',
'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through',
'what', 'window', 'with', 'yonder']
将不胜感激。谢谢
catspeake
Qyouu
拉风的咖菲猫
开满天机
相关分类