我有一个要循环运行的文件。我的文件看起来像这样:
Hello Hello
A B C D
A B C D
B C D A
B C D A
C D A B
B C D A
Hello Bye
A C D B
C D A B
A C D B
D C A B
我只通过再见运行一个循环,到空白行。
它应该返回:
 {(A, C, D, B): 2, (C, D, A, b):1, (D, C, A, B):1}
有没有一种方法可以称为“全部”来添加所有排列?
我想在不使用任何导入的情况下做到这一点。
到目前为止,我的功能如下所示:
# input_word = Hello or Bye
def file_to_dict (file, input_word):
    new_dict = {}
    new_list = []
    flag = False
    for line in f:
        if 'Hello' in line:
            continue
        if not line.strip():
            continue
        lElts = tuple(line.split(' '))
        if lElts in dRet:
            dRet[lElts] += 1
        else:
            dRet[lElts] = 1
    return dRet
有没有其他选择可以继续?
现在这给了我一个错误说:
ValueError: I/O operation on closed file