Element wise concatenate multiple lists (list of list of strings)

前端 未结 3 779
独厮守ぢ
独厮守ぢ 2020-12-20 18:54

i have a list of list of strings as below

lst = [[\'a\',\'b\',\'c\'],[\'@\',\'$\',\'#\'],[\'1\',\'2\',\'3\']]

I want to concatenate each

3条回答
  •  不思量自难忘°
    2020-12-20 19:06

    Not as elegant as yatu's answer but if you're using pandas:

    import pandas as pd
    pd.DataFrame(lst).sum(axis=0)
    
    # 0    a@1
    # 1    b$2
    # 2    c#3
    # dtype: object
    

    Pandas Series have a .tolist() method to get the expected output:

    series = pd.DataFrame(lst).sum(axis=0)
    series.tolist()
    
    # ['a@1', 'b$2', 'c#3']
    

提交回复
热议问题