有人可以解释为什么我的代码返回不匹配,因为我认为你可以用“==”比较两个字典?
import csv
import sys
import copy
def main():
# TODO: Check for command-line usage
if len(sys.argv) != 3:
sys.exit(1)
# TODO: Read database file into a variable
database = []
key = []
database_file = sys.argv[1]
d = open(database_file, "r")
reader = csv.DictReader(d)
for name in reader:
database.append(name)
copy_database = copy.deepcopy(database)
for i in range(len(copy_database)):
del copy_database[i]["name"]
for i in range(len(copy_database)):
for k in copy_database[i]:
key.append(k)
remove_dup = list(set(key))
# TODO: Read DNA sequence file into a variable
sequence_file = sys.argv[2]
s = open(sequence_file, "r")
sequence = s.read()
# TODO: Find longest match of each STR in DNA sequence
match = {}
for i in range(len(remove_dup)):
match[remove_dup[i]] = longest_match(sequence,remove_dup[i])
# TODO: Check database for matching profiles
for i in range(len(database)):
if match == copy_database[i]:
print(database[i]["name"])
print("No Match")
我可以看到我将最长的序列放入匹配字典中,它是正确的,但是当我尝试将它与没有名称键的数据库副本进行比较时,我没有得到任何命中。