python join list 2逐行列出1

时间:2016-06-08 10:36:49

标签: python string list

我有2个字符串列表,需要加入列表,因此列表2中的行被附加到列表1的每一行的末尾。排序是正确的,每个列表中的记录数相同。以下示例:

list1 =  ["A", "B" , "C"]

list2 = ["E", "F", "G"]

newlist = ["A,E", "B,F", "C,G"]

5 个答案:

答案 0 :(得分:5)

只需简单地压缩列表然后加入元组:

>>> list1 =  ["A", "B" , "C"]
>>> list2 = ["E", "F", "G"]
>>> [','.join(i) for i in zip(list1, list2)]
['A,E', 'B,F', 'C,G']

答案 1 :(得分:3)

轻松完成任务,请使用 renderer : function (oRM, oControl) { oRM.write("<div"); oRM.writeControlData(oControl); oRM.addClass("myAppDemoWTProductRating"); oRM.writeClasses(); oRM.write(">"); oRM.renderControl(oControl.getAggregation("_rating")); oRM.renderControl(oControl.getAggregation("_label")); oRM.renderControl(oControl.getAggregation("_button")); oRM.write("</div>"); oControl.someFunction(); }, someFunction: function(){ //Do something }

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-database:9.0.0'

你甚至可以为一般长度的purpouse生成它:

map

答案 2 :(得分:2)

你可以结合列表推导和内置 data.frame(...,stringsAsFactors=FALSE) 功能的强大功能:

     stringsAsFactors=TRUE;

答案 3 :(得分:0)

如果您有多个列表,则会执行以下操作:

list_of_list = [list1,list2]
[",".join(n) for n in  zip( *list_of_list )]

答案 4 :(得分:0)

这应该可以正常工作

list1 = ["A", "B" , "C"]
list2 = ["E", "F", "G"]
newlist = []
for i in range(0, len(list1)):
    newlist.append(list1[i]+","+list2[i])
print(newlist)

bash@bash:~$ python a.py 
['A,E', 'B,F', 'C,G']