![](/img/trans.png)
[英]Python How to pass specific key from list of Dictionary to Map function
[英]python 3 how to pass a dictionary from a list
我一直在將字典從列表傳遞到另一個函數時遇到問題。 我很確定這是因為我的字典在字典列表中。
例子:
我想要的是: {"part": x2f5, "color": red, "amount": 10}
當我傳遞給函數時我得到了什么: [{part": x2f5, "color": red, "amount": 10}]
if (len(order["inventory"]) >= 1):
#I want to double check here if the part is already in the order
if new_order["part"] in (i["part"] for i in order["inventory"]):
if already_in(new_order, order["inventory"]):
讓我知道是否應該添加更多信息。
你可以試試這個:
def the_function(*s):
pass
m = [{"part": x2f5, "color": red, "amount": 10}]
the_function(*m)
此解決方案將允許您將“n”個字典項從列表傳遞給the_function
。
非常感謝大家!
然而,我能夠在這里自己解決它,如果有人好奇,我就是這樣做的
for i in order["inventory"]:
if (i["part"] == new_order["part"]):
if (already_in(new_order, i)):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.