Iwan. J Iwan. J - 1 month ago 13
Python Question

Format nested list python

list=[['name1', 'maths,english'], ['name2', 'maths,science']]


I have a nested list that likes something like this, I am trying to work out how to format it so that the out put would be something like the following:

name1, maths,english
name2, maths,science


I have tried using regex to no avail. How would I go about formatting or manipulating the list output to get something like the above?

Answer

Iterate over your groups and join the items from each group using a comma.

groups = [['name1', 'maths,english'], ['name2', 'maths,science']]

for group in groups:
    print ', '.join(group)
Comments