My code does not work as expected. My partial code looks like this:
lst_of_players = []
class Player:
def __init__(self, username):
self.username = username
self.level = 1
lst_of_players.append(self)
def level_up(self):
self.level += 1
player1 = Player("Player 1")
player2 = Player("Player 2")
player3 = Player("Player 3")
def level_up_all_players():
map(lambda player: player.level_up(), lst_of_players)
I thought the players' levels would be leveled up by 1 when i call level_up_all_players func, but it does not. When I print the levels of players, they still had the levels they had before calling the function.