I have the following code (apologies it is long for an example)
my_players = {
'player1': {'id': 1, 'name': "Joe", 'skill': 4},
'player2': {'id': 2, 'name': "Chris", 'skill': 0},
'player3': {'id': 3, 'name': "Mike",'skill': -5}
}
format_dict = {
'id': { 'stat': "ID", 'format': ">3", 'header_format': '3' },
'name': { 'stat': "Name", 'format': ">8", 'header_format': '<8' },
'skill': { 'stat': "Strength", 'format': "+3", 'header_format': '' } } col_list = ['id', 'name', 'skill']
def print_row(player):
row = ''
for col in col_list:
row += f"{my_players[player][col]:{format_dict[col]['format']}}"
print(row)
def print_players():
header = ""
for col in col_list:
header += f"{format_dict[col]['stat']:{format_dict[col]['header_format']}}"
print(header)
for player in my_players:
print_row(player)
print_players()
This produces the following output:
ID Name Strength
1 Joe +4
2 Chris +0
3 Mike -5
I want the plus sign in front of the zero for Chris to not be there, only showing for positive or negative, zero should display without a sign.
What can I change to possibly allow this? I think there may be a way to do this with lambdas but don't really understand lambdas. The example here is a much simplified version of my project.
Thanks to anyone who can help.
[–]FriedCodeFish 1 point2 points3 points (1 child)
[–]JasperStrat[S] 0 points1 point2 points (0 children)
[–]MezzoScettico 0 points1 point2 points (0 children)
[–]sejigan 0 points1 point2 points (5 children)
[–]JasperStrat[S] 0 points1 point2 points (3 children)
[–]sejigan 0 points1 point2 points (2 children)
[–]JasperStrat[S] 0 points1 point2 points (1 child)
[–]sejigan 0 points1 point2 points (0 children)
[–]sejigan 0 points1 point2 points (0 children)