def getValues(myDict):
return list(myDict.items())[0][1] # <-- my code returns only 1 value, I need all values
courses = {'CPS141':60, 'CSS210':30, 'CPS161':20}
print(getValues(courses))
預期輸出:[60,30,20]
uj5u.com熱心網友回復:
您可以使用串列理解:
[value for key, value in myDict.items()]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431530.html
標籤:python-3.x 字典
上一篇:從元組串列構建字典串列
