我想在添加值之前添加密钥。在当前阶段的代码它正好相反..
enter def px():
for i in x:
print(i, "equal" , x[i] )
x = {"a" : 1, "b" : 2, "c" : 3, "d" : 4}
px()
x[input("Add a letter ")] = input("Add a number ")
px() here
有人能帮忙吗?
答案 0 :(得分:1)
询问密钥,然后询问值,然后在字典中输入:3个单独的步骤:
k = input("Add a letter ")
v = input("Add a number ")
x[k] = v