concatenate the elements in each list of a list of lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • antar2

    concatenate the elements in each list of a list of lists

    I already asked a similar question, but encounter problems with
    python...
    How can I concatenate the elements in each list of a list of lists

    list_of_listsA =

    [['klas*', '*', '*'],
    ['mooi*', '*', '*', '*'],
    ['arm*', '*', '*(haar)']]

    wanted result:

    list_of_listsA =

    [['klas* * *']
    ['mooi* * * *']
    ['arm* * *(haar)']]

    Thanks a lot !

  • Chris

    #2
    Re: concatenate the elements in each list of a list of lists

    On Jul 23, 5:33 pm, antar2 <desoth...@yaho o.comwrote:
    I already asked a similar question, but encounter problems with
    python...
    How can I concatenate the elements in each list of a list of lists
    >
    list_of_listsA =
    >
    [['klas*', '*', '*'],
    ['mooi*', '*', '*', '*'],
    ['arm*', '*', '*(haar)']]
    >
    wanted result:
    >
    list_of_listsA =
    >
    [['klas* * *']
    ['mooi* * * *']
    ['arm* * *(haar)']]
    >
    Thanks a lot !
    Nice and easy. :)
    >>list_of_lists A = [['klas*', '*', '*'],
    ['mooi*', '*', '*', '*'],
    ['arm*', '*', '*(haar)']]
    >>[' '.join(l) for l in list_of_listsA]
    ['klas* * *', 'mooi* * * *', 'arm* * *(haar)']

    Comment

    • Michael Schneider

      #3
      Re: concatenate the elements in each list of a list of lists

      Am Wed, 23 Jul 2008 08:33:57 -0700 wrote antar2:
      I already asked a similar question, but encounter problems with
      python...
      How can I concatenate the elements in each list of a list of lists
      >
      list_of_listsA =
      >
      [['klas*', '*', '*'],
      ['mooi*', '*', '*', '*'],
      ['arm*', '*', '*(haar)']]
      >
      wanted result:
      >
      list_of_listsA =
      >
      [['klas* * *']
      ['mooi* * * *']
      ['arm* * *(haar)']]
      >
      Thanks a lot !
      Hello,

      maybe this will help:

      In [5]: list_of_listsA = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'],
      ['arm*', '* ', '*(haar)']]
      In [6]: s = ""
      In [7]: print [[s.join(item)] for item in list_of_listsA]
      [['klas***'], ['mooi****'], ['arm** *(haar)']]

      regards
      Michael

      Comment

      • Niklas Norrthon

        #4
        Re: concatenate the elements in each list of a list of lists

        On 23 Juli, 17:33, antar2 <desoth...@yaho o.comwrote:
        I already asked a similar question, but encounter problems with
        python...
        How can I concatenate the elements in each list of a list of lists
        >
        list_of_listsA =
        >
        [['klas*', '*', '*'],
        ['mooi*', '*', '*', '*'],
        ['arm*', '*', '*(haar)']]
        >
        wanted result:
        >
        list_of_listsA =
        >
        [['klas* * *']
        ['mooi* * * *']
        ['arm* * *(haar)']]
        >
        Thanks a lot !
        wanted_result = [[item] for item in map(' '.join, list_of_listsA)]

        Comment

        Working...