How to concatenate element-wise two lists in Python?

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

    If you wanted to concatenate arbitrary number of lists, you could do this:

    In [1]: lists = [["a", "b", "c"], ["m", "n", "o"], ["p", "q", "r"]] # Or more
    
    In [2]: lists
    Out[2]: [['a', 'b', 'c'], ['m', 'n', 'o'], ['p', 'q', 'r']]    
    
    In [4]: list(map("".join, zip(*lists)))
    Out[4]: ['amp', 'bnq', 'cor']
    

提交回复
热议问题