我有一个这样的列表:
[[1,2,3],[4,5,6]]
我想将每个内部列表的第一个元素乘以 10。所以预期的输出将是这样的:
[[10,2,3],[40,5,6]]
我怎样才能做到这一点?
最佳答案
试试这个:
my_list = [[1,2,3],[4,5,6]]
for i in my_list:
i[0] *= 10 # multiply the first element of each of the inner lists by 10
print(my_list)
输出:
[[10, 2, 3], [40, 5, 6]]
关于python - 在Python中,如何将列表中的第一个元素乘以一个数字(在列表的列表中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35882104/