Re: convert list of lists to list

2008-07-22 Thread Raymond Hettinger
On Jul 22, 8:25 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > if there's only one level of recursion, and the lists aren't too long, > you can simply do: > >      sum(list_of_lists, []) > > (this has quadratic performance, so don't use it for large structures) For linear performance, you can use

Re: convert list of lists to list

2008-07-22 Thread Bruno Desthuilliers
antar2 a écrit : Is there a way to convert list_of_listsA to list_of_listsB, where one list in listof lists A is one element of listB? list_of_listsA: [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'], ['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']] listB: ['klas* * *', 'mooi* *

Re: convert list of lists to list

2008-07-22 Thread Fredrik Lundh
Fredrik Lundh wrote: ['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * * *'] if there's only one level of recursion, and the lists aren't too long, you can simply do: sum(list_of_lists, []) oops. that's what you get for taking the subject line too literally... -- h

Re: convert list of lists to list

2008-07-22 Thread Peter Otten
antar2 wrote: > Is there a way to convert list_of_listsA to list_of_listsB, where one > list in listof lists A is one element of listB? > > list_of_listsA: > [['klas*', '*', '*'], > ['mooi*', '*', '*', '*'], > ['koe'], > ['arm*', '*', '*(haar)'], > ['groei*', '*', '*', '*', '*']] > > listB: > ['

Re: convert list of lists to list

2008-07-22 Thread Stephen Johnson
list_A = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'], ['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']] list_B = [] for inner_list in list_A: #join elements of list into a string with separator ' ' list_B.append(' '.join(inner_list)) print list_B Output: ['kl

Re: convert list of lists to list

2008-07-22 Thread Fredrik Lundh
antar2 wrote: Is there a way to convert list_of_listsA to list_of_listsB, where one list in listof lists A is one element of listB? list_of_listsA: [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'], ['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']] listB: ['klas* * *', 'mooi* *

convert list of lists to list

2008-07-22 Thread antar2
Is there a way to convert list_of_listsA to list_of_listsB, where one list in listof lists A is one element of listB? list_of_listsA: [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['koe'], ['arm*', '*', '*(haar)'], ['groei*', '*', '*', '*', '*']] listB: ['klas* * *', 'mooi* * * *, 'koe', 'arm*