尝试使用其他列表检查列表时遇到问题

时间:2014-09-25 17:50:11

标签: python list file dictionary external

我的程序的一部分允许用户检查他们输入的线索是否正确,解决的版本位于名为solve.txt的外部文件中...到目前为止,我有下面显示的代码但是它只是显示程序开头的三个线索配对是正确的,而不是我在整个程序中添加的线索配对。我认为这只是一些小问题,但我对改变什么感到困惑。

到目前为止,这是我的代码......

def check_clues():
    # Dictionary to hold all of the symbol/letter combos
    coded_dict = {}

    # Go through each symbol/letter combination together
    with open("words.txt") as fw, open("solved.txt") as fs:
        for fw_line, fs_line in zip(fw, fs):
            for fw_symbol, fs_letter in zip(fw_line.strip(), fs_line.strip()):
                # Add the symbol/letter combination to the dictionary
                coded_dict[fw_symbol] = fs_letter

    correct_clues = []
    with open("clues.txt") as fc:
        for fc_line in fc:
            # If the symbol is in the dictionary and the letter matches the symbol
            if fc_line[1] in coded_dict and coded_dict[fc_line[1]] == fc_line[0]:
                # Add a correct clue to your list
                correct_clues.append(fc_line.strip())

    print("You got a total of {0} correct: {1}".format(len(correct_clues), ", ".join(correct_clues)))

if __name__ == "__main__":
    check_clues()

以下是每个文件中的内容链接......

http://www.codeshare.io/vgwrC

如果需要,我会为我的所有程序添加代码......

0 个答案:

没有答案