Data:
game_match = {'G02': ['MineCraft', 'S', '5', 5, 3, 2, 0, 0], 'G05': ['Hopscotch', 'N', '2', 5, 3, 2, 0, 0], 'G07': ['Dominoes', 'S', '5', 5, 2, 3, 0, 2], 'G08': ['Chess', 'N', '3', 5, 2, 3, 1, 2], 'G10': ['Monopoly', 'N', '3', 5, 1, 4, 2, 2]}
For each key and values in the dictionary I want to print:
- key, values[0], values[1], values[2], values[3], values[4]
My code:
dash = '-' * 48
print(f'GameID{" ":7}Name{" ":7}Weight{" ":2}Nplayer{" ":2}Win{" ":2}', end='')
print('')
print(dash)
for k, v in game_match.items():
print(f'{k:10}{v[0]:^5}({v[1]}){" ":^5}{v[2]:6}{v[3]:3}{" ":6}{v[4]}')
Output:
GameID Name Weight Nplayer Win
------------------------------------------------
G02 MineCraft(S) 5 5 3
G05 Hopscotch(N) 2 5 3
G07 Dominoes(S) 5 5 2
G08 Chess(N) 3 5 2
G10 Monopoly(N) 3 5 1
I want to print the data above with equal spacing, but seem to fail. What code or format is the right one for this?
Expected Output:
GameID Name Weight Nplayer Win
------------------------------------------------
G02 MineCraft(S) 5 5 3
G05 Hopscotch(N) 2 5 3
G07 Dominoes(S) 5 5 2
G08 Chess(N) 3 5 2
G10 Monopoly(N) 3 5 1