只留下值最小的键,我不能使用 min()
函数。
移动 OP 从他的评论中尝试的代码:-
for i in key:
if dictionary[i]<dictionary[key]:
dictionary.pop(key)
elif dictionary[i]==dictionary[key]:
print (dictionary[i])
以及来自其他评论的代码:
dictionary={'A': 3, 'B': -2, 'C': -1, 'D': -3}
for key in dictionary:
print ("Keys and values>", key,end= '')
print (dictionary[key])
print (dictionary)
for i in key:
if dictionary[i]<dictionary[key]:
dictionary.pop(key)
elif dictionary[i]==dictionary[key]:
print ("The minimum is",dictionary[i])