Reputation: 83
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?
Upvotes: 0
Views: 1752
Reputation: 5552
In Python3 you could use format() as described in PEP 3101
fmt_groups = "\n".join(["{},{}".format(*group) for group in groups])
print(fmt_groups)
Upvotes: 0
Reputation: 91545
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)
Upvotes: 5