convert list of lists to list
Stephen Johnson
diordna at gmail.com
Tue Jul 22 11:27:56 EDT 2008
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:
['klas* * *', 'mooi* * * *', 'koe', 'arm* * *(haar)', 'groei* * * * *']
-Steve Johnson
On Jul 22, 2008, at 11:10 AM, 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* * * *, 'koe', 'arm* * * (haar)', 'groei* * * *
> *']
>
> Thankx!
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080722/6e140e1f/attachment-0001.html>
More information about the Python-list
mailing list