如何在python中的现有列表中插入第三个嵌套列表?

Ash*_*tap 2 python

我有一个列表ilist,看起来像这样:

['TCS', 1968, ['Mumbai', 'Delhi', 'Kochi', 'Banglore', 'Pune'], 'Wipro', 1981, ['Pune', 'Banagalore', 'Pune'], 'Infosys', 1945, ['Bangalore', 'Chandigarh', 'Pune']]
Run Code Online (Sandbox Code Playgroud)

现在我想以列表的形式插入一些额外的值,如下面突出显示的那样:

['TCS', 1968, ['Mumbai', 'Delhi', 'Kochi', 'Banglore',**["ITPL","Whiteflied"]**, 'Pune'], 'Wipro', 1981, ['Pune', 'Banagalore', 'Pune'], 'Infosys', 1945, ['Bangalore', 'Chandigarh', 'Pune']]
Run Code Online (Sandbox Code Playgroud)

我想尝试插入方法,我可以使用它来插入第二个嵌套循环,如下所示:

ilist.insert(2,['Mumbai','Delhi','Kochi','Banglore','Pune'])
Run Code Online (Sandbox Code Playgroud)

但是因为insert方法只接受一个参数,即我们要插入值的索引.我们如何能够如下所示:

ilist.insert(2,3,"ITPL","Vedhi","Electronic city")  
Run Code Online (Sandbox Code Playgroud)

这是错误的.我所知道的将永远存在:

Traceback (most recent call last):
  File "G:/Python Programs/Loops.py", line 41, in <module>
ilist.insert(2,3,"ITPL","Vedhi","Electronic city")
TypeError: insert() takes exactly 2 arguments (5 given)
Run Code Online (Sandbox Code Playgroud)

那么做这项任务的替代方案是什么呢?除了宣布新的清单.

Dan*_* D. 5

您必须索引第一个列表,然后插入该索引的列表中:

ilist[2].insert(3, ["ITPL","Vedhi","Electronic city"])
Run Code Online (Sandbox Code Playgroud)