Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to add a newline after each append in list

I have a list of tuples in rows which I need to append to another list and add a newline after each entry I tried everything I can think of but I cant seem to do it properly
here is the code:

niz = ["""
(5, 6, 4)
(90, 100, 13), (5, 8, 13), (9, 11, 13)
(9, 11, 5), (19, 20, 5), (30, 34, 5)
(9, 11, 4)
(22, 25, 13), (17, 19, 13)
"""]

list = []
    for n in niz:
        list.append(n)   
    list = '\n'.join(list)
    print(list)

This is the closest I get:

(5, 6, 4)
(90, 100, 13), (5, 8, 13), (9, 11, 13)
(9, 11, 5), (19, 20, 5), (30, 34, 5)
(9, 11, 4)
(22, 25, 13), (17, 19, 13)

But I need it to be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[(5, 6, 4),
 (90, 100, 13), (5, 8, 13), (9, 11, 13),
 (9, 11, 5), (19, 20, 5), (30, 34, 5),
 (9, 11, 4),
 (22, 25, 13), (17, 19, 13)]

>Solution :

Join using ",\n" instead of just "\n"and append the first "[" and last "]" characters

list = []
for n in niz:
    list.append(n)   
list = '[' + ',\n'.join(list) + ']'

print(list)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading