【问题标题】:is there a way to join list of strings in sublist有没有办法加入子列表中的字符串列表
【发布时间】:2013-04-03 13:20:38
【问题描述】:

我有以下子列表:

[['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]

但是可以加入子列表中的列表吗?

[['ab'], ['cd'], ['ef'], ['g']]

【问题讨论】:

    标签: python list join sublist


    【解决方案1】:
    >>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
    >>> [[''.join(x)] for x in L]
    [['ab'], ['cd'], ['ef'], ['g']]
    

    【讨论】:

      【解决方案2】:

      另外,你可以使用地图

      >>> L = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g']]
      >>> map(lambda x: [''.join(x)], L)
      [['ab'], ['cd'], ['ef'], ['g']]
      

      【讨论】:

        猜你喜欢
        • 2021-05-03
        • 2022-07-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-25
        • 2020-04-16
        相关资源
        最近更新 更多