求教如何对二维甚至多维列表进行增、删、改操作?
Topic sourceL = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa'] ] L[0] = ['Apple', 'Google', 'Microsoft'] L[0].insert(1, 'Facebook') print (L)
L = [ ['Apple', 'Google', 'Microsoft'] ['Java', 'Python', 'Ruby', 'PHP'] ['Adam', 'Bart', 'Lisa'] ]
L[0].insert(1,'Facebook')
print(L)
- 1
司徒空_3240
例如:在子列表 ['Apple', 'Google', 'Microsoft']中Google前面插入Facebook。网上没找到有用信息,求教各位。 如下代码会报错:list index out of range.
-- coding:utf-8 --
L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa'] ] L.insert([0][1],'Facebook') print(L)