How to concatenate element-wise two lists in Python?

后端 未结 8 2508
春和景丽
春和景丽 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:44

    inputs:

    a = [0, 1, 5, 6, 10, 11] 
    b = ['asp1', 'asp1', 'asp1', 'asp1', 'asp2', 'asp2']
    
    concat_func = lambda x,y: x + "" + str(y)
    
    list(map(concat_func,b,a)) # list the map function
    

    output:

    ['asp10', 'asp11', 'asp15', 'asp16', 'asp210', 'asp211']
    

提交回复
热议问题