3 回答
TA贡献1824条经验 获得超6个赞
使用负索引。
前任:
myList = [[1, 'A1', 100, '1001', '1', '1001', 'None'],
[2, 'B1', 101, '3008', '2', '3008', 'bb'],
[3, 'C1', 102, '607', '3', '607', 'None']]
myList = [i[:-1] + [""] if i[-1] == 'None' else i for i in myList ]
print(myList)
输出:
[[1, 'A1', 100, '1001', '1', '1001', ''],
[2, 'B1', 101, '3008', '2', '3008', 'bb'],
[3, 'C1', 102, '607', '3', '607', '']]
TA贡献1880条经验 获得超4个赞
使用负索引:
for subList in myList:
if subList[-1] == 'None':
subList[-1] = ' '
myList
# [[1, 'A1', 100, '1001', '1', '1001', ' '],
# [2, 'B1', 101, '3008', '2', '3008', 'bb'],
# [3, 'C1', 102, '607', '3', '607', ' ']]
TA贡献1836条经验 获得超3个赞
myList = [[1, 'A1', 100, '1001', '1', '1001', 'None'],[2, 'B1', 101, '3008', '2', '3008', 'bb'],[3, 'C1', 102, '607', '3', '607', 'None']]
for i in range(len(myList)):
print(i)
print(type(myList[i][len(myList[i])-1]))
if(myList[i][len(myList[i])-1]== 'None'):
myList[i][len(myList[i])-1]=' '
print(myList)
添加回答
举报