遍历list时,又对list里的元素进行修改的示例代码
ee = [[1,2,3],[4,5,6]]
dd= []
for item in ee:
dd.append(item[1:])
print(dd)
修改list中所有元素类型的示例代码(转自CSDN博客)
方法1:
new = list()
a= ['1','2','3']
for x in a:
new.append(int(x))
print(new)
方法2:
a= ['1','2','3']
b= [int(x) for x in a]
print(b)
方法3:
a= ['1','2','3']
print(map(int, a))