我需要存储1个文件中的密钥和另一个文件中的值。与第1个文件一样,该文件的第一行是'a',第二个文件的第一行是20。字典应该是a:20
尝试这样的事情:
dictionary = {}
with open("file1.txt") as file1, open("file2.txt") as file2:
for key, value as zip(file1, file2):
key = key.strip()
value = value.strip() # If all the values must be integers, do int(value.strip())
dictionary[key] = value