我想创建一个包含列表字典的新字典。我的代码是:
SERVICES = "FTP Download", "FTP Upload", "HTTP"
received = dict.fromkeys(SERVICES , {'MS1':[]})
n = 0
for service in SERVICES:
received[service]['MS1'].append(n)
n += 1
print(received)
我得到了什么。尽管我使用了不同的键,但我在每本字典中都得到了相同的列表。
我的输出是:{'FTP Download': {'MS1': [0, 1, 2]}, 'HTTP': {'MS1': [0, 1, 2]}, 'FTP Upload': {'MS1': [0, 1, 2]}}
从键创建空白字典的正确方法是什么?