我有一個簡單的解釋:從字典中創建元組列表?
{"keyy":{"key": "value", "cey": "value"}, "kaye":{"key": "value"}}
,我想編碼爲「上下文感知」的元組:
[("keyy","key","value"), ("keyy","cey","value"), ("kaye","key","value")]
我嘗試用ValueError異常:值過多解壓:
if __name__=='__main__':
mydict={"keyy":{"key": "value", "cey": "value"}, "kaye":{"key", "value"}}
mytuplelist=[tuple(k,v,val) for (k,v) in [(key,val) for (key,val) in mydict]]
print mytuplelist
我該如何去創建這個元組列表?
我會用我的嘗試編輯它 – user1438003
'tuple(k,v,val)'應該是'(k,v,val)'next –
是的,我知道,只是想明確地表明我是什麼試圖去做。 – user1438003