[Solved] How to use element of list as object for a class?


It would work by putting players into a dict:

class Character(object):
    def __init__(self):
        self.NAME = ''
        self.life = 50

players = ["red","green","blue","yellow"]
dict_players = {}

for player in players:
    dict_players[player] = Character()

However, printing would only work if you create a __str__ method for your class.

solved How to use element of list as object for a class?