我的项目很基础。。。我需要一个葛底斯堡地址的文本文件,并计算字数和唯一字数。我几乎一路走到了最后,但它的重复计算的词是一样的,只是一个大写的第一个字母-即,但。我不知道该怎么解决这个问题:(这是我目前所掌握的:
def main():
getty = open('Gettysburgaddress.txt','r')
lines = getty.readlines()
getty.close()
index = 0
while index < len(lines):
lines[index] = lines[index].rstrip('\n')
index += 1
words = [word for line in lines for word in line.split()]
size = len(words)
print('\nThere are', size,'words in the Gettysburg Address.\n')
unique = list(set(words))
size_unique = len(unique)
print('There are', size_unique,'unique words in the Gettysburg Address.\n')
unique.sort()
print('Sorted order of unique words:', unique)
close = input('')
main()
目前没有回答
相关问题 更多 >
编程相关推荐