Python How to pair two list by lambda and map

后端 未结 5 1414
北海茫月
北海茫月 2021-01-17 13:56

For example, I have following two lists

listA=[\'one\', \'two\' , \'three\'] listB=[\'apple\',\'cherry\',\'watermelon\']

How can I pair those two lists to

5条回答
  •  天涯浪人
    2021-01-17 14:50

    Using list comprehension and zip:

    listA=['one', 'two' , 'three']
    
    listB=['apple','cherry','watermelon']
    
    new_list = [a+" "+b for a, b in zip(listA, listB)]
    

    Output:

    ['one apple', 'two cherry', 'three watermelon']
    

提交回复
热议问题