concatenate the elements in each list of a list of lists

Discussion in 'Python' started by antar2, Jul 23, 2008.

  1. antar2

    antar2 Guest

    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 !
    antar2, Jul 23, 2008
    #1
    1. Advertising

  2. antar2

    Chris Guest

    On Jul 23, 5:33 pm, antar2 <> wrote:
    > 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_listsA = [['klas*', '*', '*'],

    ['mooi*', '*', '*', '*'],
    ['arm*', '*', '*(haar)']]
    >>> [' '.join(l) for l in list_of_listsA]

    ['klas* * *', 'mooi* * * *', 'arm* * *(haar)']
    Chris, Jul 23, 2008
    #2
    1. Advertising

  3. 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
    Michael Schneider, Jul 23, 2008
    #3
  4. On 23 Juli, 17:33, antar2 <> wrote:
    > 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)]
    Niklas Norrthon, Jul 23, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    417
    Tjerk Wolterink
    Nov 3, 2004
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    390
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. antar2
    Replies:
    2
    Views:
    379
    Bighead
    Jul 17, 2008
  4. Nezhate

    How to concatenate Matrix's elements ?

    Nezhate, Jul 21, 2008, in forum: C Programming
    Replies:
    0
    Views:
    368
    Nezhate
    Jul 21, 2008
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    863
Loading...

Share This Page