def divisble_numbers(a_list, terms):
b_list = [x for x in [a_list] if (x % [terms] == 0)]
c_list = [x for x in b_list if all(x % [terms] == 0)]
return c_list
divisble_numbers([2,3,5,1,6,7,8,9,10,11,12], [2,3])
返回此錯誤:TypeError: unsupported operand type(s) for %: 'int' and 'list'
有一個問題與列表理解
我試圖去得到那個是兩個術語整除的索引列表。我對我遇到的錯誤感到困惑,對列表理解很陌生會感謝任何幫助。
一個帶有列表的整數的mod應該等於什麼? 'x%[term]'應該給你什麼? –