我在理解递归时遇到了困难。我正在尝试构建一个字典,当一个元组列表包含(名称,价格)时,我想确保价格小于预算,并创建一个字典,其中名称是键,价格是值。我一直收到一本空字典,我不知道为什么。任何帮助都将不胜感激。
def findstore(storelist, budget):
store_dict = {}
for key, value in storelist:
if value in storelist < budget:
value = findstore(value)
store_dict[key] = value
return store_dict
stores = [('Shaws', 2.50), ('PriceChopper', 3.99)]
budget = 2.99发布于 2020-11-03 04:27:09
我想你应该用python来理解这个-
stores = [('Shaws', 2.50), ('PriceChopper', 3.99), ('TheClipper', 1.99)]
budget = 2.99
dd = { s: p for (s, p) in stores if p <= budget }
print(dd){'Shaws': 2.5, 'TheClipper': 1.99}https://stackoverflow.com/questions/64651339
复制相似问题