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

List within a list formatting


index = 0
player_list = [['Bruce Wayne', 5, 5, 0, 0, 100, 15],['Jessica Jones', 12, 0, 6, 6, 10, 6],['Johnny Rose', 6, 2, 0, 4, 20, 10],['Gina Linetti', 7, 4, 0, 3, 300, 15],['Buster Bluth', 3, 0, 2, 1, 50, 1]]

while index < len(player_list):

    player_list2 = player_list[index]
    index +=1
    
    index_1 = 0 
    while index_1 < len(player_list2):
        print(player_list2[index_1])
        index_1 +=1

I want the list to be printed in the following format:

Bruce Wayne 5 5 0 0 100 15 
Jessica Jones 12 0 6 6 10 6
Johnny Rose 6 2 0 4 20 10
Gina Linetti 7 4 0 3 300 15
Buster Bluth 3 0 2 1 50 1

I’ve tried sep and end but they do not seem to work.

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

>Solution :

You could use string join here:

player_list = [['Bruce Wayne', 5, 5, 0, 0, 100, 15],['Jessica Jones', 12, 0, 6, 6, 10, 6],['Johnny Rose', 6, 2, 0, 4, 20, 10],['Gina Linetti', 7, 4, 0, 3, 300, 15],['Buster Bluth', 3, 0, 2, 1, 50, 1]]
for player in player_list:
    print ' '.join([str(x) for x in player])

This prints:

Bruce Wayne 5 5 0 0 100 15
Jessica Jones 12 0 6 6 10 6
Johnny Rose 6 2 0 4 20 10
Gina Linetti 7 4 0 3 300 15
Buster Bluth 3 0 2 1 50 1
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