How to concatenate element-wise two lists in Python?

后端 未结 8 2493
春和景丽
春和景丽 2020-11-29 02:24

I have two lists and I want to concatenate them element-wise. One of the list is subjected to string-formatting before concatenation.

For example :

         


        
相关标签:
8条回答
  • 2020-11-29 02:57

    Using zip

    [m+str(n) for m,n in zip(b,a)]
    

    output

    ['asp10', 'asp11', 'asp15', 'asp16', 'asp210', 'asp211']
    
    0 讨论(0)
  • 2020-11-29 03:07
    b = ['asp1', 'asp1', 'asp1', 'asp1', 'asp2', 'asp2']
    aa = [0, 1, 5, 6, 10, 11]
    new_list =[]
    if len(aa) != len(b):
         print 'list length mismatch'
    else:
        for each in range(0,len(aa)):
            new_list.append(b[each] + str(aa[each]))
    print new_list
    
    0 讨论(0)
提交回复
热议问题