1
我有一個字典和格式是使用計算字典鍵和類型錯誤
key1: [list of number]
key2: [list of number]
等...
鍵是一個數,其中KEY1 < KEY2 <等...
我我試圖選擇所有最後的n
列表,我想計算它。
x = 0
for something in dict:
if something >= max(dict.keys()) - n:
x += sum(dict[something]) // len(dict[something])
,但我得到:
TypeError: unsupported operand type(s) for -: 'str' and 'int'
and it said the error come from the 'if something >= max(dict) - n:'
請幫助...
你需要在你的例子中更具體一些。看看如何製作[mcve]。 –