-1

I am very new to Python and have a little knowledge on Object-Oriented Programming. Below is an extract of my code and it does work as intended however I was just wondering if there was an easier to store the team names as an instance by using maybe a loop.

It would take a very long time if I wanted to add every team in the world (211 teams) as a separate instance. The excel file that Panda's is reading contains all of the team names and stats required for this to work.

import pandas as pd
fixtures = pd.read_excel(r'C:\Users\Alex\Desktop\Python\Football\Fixtures.xlsx')

class Team():
    def __init__(self, win, draw, loss, gf, ga):
        self.win = win
        self.draw = draw
        self.loss = loss
        self.gf = gf
        self.ga = ga
        self.points = win*3 + draw
        self.games = win + draw + loss


wins = list(fixtures['Won'])
draws = list(fixtures['Drawn'])
losses = list(fixtures['Lost'])
scored = list(fixtures['GF'])
conceded = list(fixtures['GA'])

Arsenal = Team(wins[0], draws[0], losses[0], scored[0], conceded[0])

Aston_Villa = Team(wins[1], draws[1], losses[1], scored[1], conceded[1])

Brighton = Team(wins[2], draws[2], losses[2], scored[2], conceded[2])

Burnley = Team(wins[3], draws[3], losses[3], scored[3], conceded[3])

Chelsea = Team(wins[4], draws[4], losses[4], scored[4], conceded[4])

Crystal_Palace = Team(wins[5], draws[5], losses[5], scored[5], conceded[5])

Everton = Team(wins[6], draws[6], losses[6], scored[6], conceded[6])

Fulham = Team(wins[7], draws[7], losses[7], scored[7], conceded[7])

etc....

1 Answers1

0

You do not. You use a dictionary.


teams = {
'Arsenal': Team(wins[0], draws[0], losses[0], scored[0], conceded[0]),
'Aston_Villa': Team(wins[1], draws[1], losses[1], scored[1], conceded[1]),
}