如何将列表 a python 的元素插入列表?
How to insert element of list a python into list?
我有一个清单
a = [['mf1234','james','22'],['mcs345','Anee','22']]
b = ['man','women]
我想把列表b的成员插入一个赞
c = [['mf1234','james','22','man'],['mcs345','Anne','23','women]]
关于如何做到这一点有什么建议吗?
如果您要在 a
中每个列表的末尾插入 b
中的项目,enumerate()
and append()
是您的选择。
for idx,item in enumerate(b):
a[idx].append(item)
print a
>>> [['mf1234', 'james', '22', 'man'], ['mcs345', 'Anee', '22', 'women']]
我有一个清单
a = [['mf1234','james','22'],['mcs345','Anee','22']]
b = ['man','women]
我想把列表b的成员插入一个赞
c = [['mf1234','james','22','man'],['mcs345','Anne','23','women]]
关于如何做到这一点有什么建议吗?
如果您要在 a
中每个列表的末尾插入 b
中的项目,enumerate()
and append()
是您的选择。
for idx,item in enumerate(b):
a[idx].append(item)
print a
>>> [['mf1234', 'james', '22', 'man'], ['mcs345', 'Anee', '22', 'women']]