我想使用while
循环而不是for
循环编写此代码
我尝试做所有事情,将字典转到列表,然后删除项目,但这没用。
Journal = {12: 'ASUS', 2: 'HP', 57: 'IBM', 3: 'DELL', 689: 'APPLE'}
inputi = input("five keys ").split(",")
num = len(inputi)
for keys, values in list(Journal.items()):
Journal.pop(keys)
num -= 1
Journal[inputi[num]] = values
答案 0 :(得分:0)
for keys, values in list(Journal.items()):
Journal.pop(keys)
num -= 1
Journal[inputi[num]] = values
jit = Journal.items()
while(True):
try:
key, value = next(jit)
except StopIteration:
break
Journal.pop(key)
num -= 1
Journal[inputi[num]] = value