如何獲取以/包含“兩個”字串開頭的鍵的 mydict 子集?
mydict = {'one,a': 1, 'one,b': 2, 'two,a': 3, 'two,b': 3}
{'two,a': 3, 'two,b': 3}
uj5u.com熱心網友回復:
用字典理解。
subdict = {key: value for (key, value) in mydict.items() if 'two' in key}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431524.html
