【发布时间】:2018-05-30 14:05:16
【问题描述】:
代码
dict = {}
flag = True
while True:
length = raw_input('enter length')
amount = raw_input('enter amount')
if (length == 'quit') or (amount == 'quit'):
flag = False
continue
我想添加代码所以
if key in dict:
# previous value + amount
# insert the new value to the key
else:
dict[length] = amount
例如:
我的输入是:13000,2
比:12000: 2
再次:13000: 2
所以 dict 将包括 13000: 4 和 12000: 2
【问题讨论】:
-
if length in dict?
标签: python dictionary