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
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* *
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
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:
> ['
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
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* *
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*