第13942题 程序题
Python程序填空:统计指定文本文件中区分大小写的不同单词个数

题目要求

统计英文文本中出现的不同单词个数:读取只包含英文和标点的文件/data/abc.txt,文件中单词与单词之间用1个空格或标点符号隔开,文末以标点符号结尾,区分单词大小写,输出该文本中所出现的不同单词个数。

请在以下Python程序的划线处填入合适的代码:

f = open('/data/__①__', 'r')
text = f.read()
lst = []
s = ""
def judge(__②__):
    if st in lst:
        return False
    else:
        return True
for i in range(len(text)):
    c = __③__
    if "a" <= c <= "z" or "A" <= c <= "Z":
        s = s + c
    else:
        if judge(s):
            lst.append(s)
        s = ""
print("出现的不同单词个数为:", len(lst))
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
编辑模式
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析