我正在将列表“a”中的每个偶数整数元素加倍,然后将结果存储回“a”中。列表'a'是一个整数列表。目前为止:
def double(item):
if [x for x in item]%2 == 0:
return [x * 2 for x in item]
else:
return [x in item]
给我这个错误:
TypeError: unsupported operand type(s) for %: 'list' and 'int'
我怎样才能把这个列表转换成int?在
Tags:
几个问题:
if
)应应用于for
循环(或列表理解)中item
的每个元素。在%
)应用于列表。在[x * 2 for x in item]
-这个分支将为项目中的每个数字创建一个列表。在[True]
或{代码:
相关问题 更多 >
编程相关推荐