-1

I loop through the list of all 32 NFL teams and through each iteration the team name is held in team. I am trying to create a Team() object referenced by the team name for each team. The first iteration team = 'arizona_cardinals'.

for team in teams:
 # I am looking for a way to say 'arizona_cardinals = Team()'
 team.text = Team() # something like this but this is obviously wrong
Justin
  • 1,329
  • 3
  • 16
  • 25
  • 2
    This is almost always a **bad** idea. Use a dictionary, with the team name as the key. – Prune Oct 23 '20 at 21:30
  • 1
    One way might be to use an object with keys as team names? Then you can do `teams[team] = Team()` – Raphael Koh Oct 23 '20 at 21:31
  • Does this answer your question? [Using a string variable as a variable name](https://stackoverflow.com/questions/11553721/using-a-string-variable-as-a-variable-name) – mkrieger1 Oct 23 '20 at 22:06

1 Answers1

1

Perhaps you want to make a dict with the team names as the key:

team_dict = {team:Team() for team in teams}
quamrana
  • 37,849
  • 12
  • 53
  • 71