You could have some kind of equivalence mapping:
equivalents = {"Arsenal": ["ARS",],
"Manchester United": ["MNU", "ManUtd"], ...}
And use this to process your data:
>>> name = "ManUtd"
>>> for main, equivs in equivalents.items():
if name == main or name in equivs:
name = main
break
>>> name
"Manchester United"
This allows you to easily see what you consider to be the "canonical name" for the team (i.e. the key) and other names that are considered to be the same team (i.e. the list value).
If you do go down the class route, you should make the list of team tuples a class attribute:
class Team:
TEAMS = [("Arsenal", "ARS"), ("Manchester United", "MNU", "ManUtd"), ...]
def __init__(self, name):
if not any(name in names for names in self.TEAMS):
raise ValueError("Not a valid team name.")
self.name = name
def __eq__(self, other):
for names in self.TEAMS:
if self.name in names and other.name in names:
return True
return False
The output from this:
>>> mnu1 = Team("ManUtd")
>>> mnu2 = Team("MNU")
>>> mnu1 == mnu2
True
>>> ars = Team("ARS")
>>> ars == mnu1
False
>>> fail = Team("Not a name")
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
fail = Team("Not a name")
File "<pyshell#43>", line 7, in __init__
raise ValueError("Not a valid team name.")
ValueError: Not a valid team name.
Alternatively, just a simple function would do the same job if your Team
won't have other attributes:
def equivalent(team1, team2):
teams = [("Arsenal", "ARS"), ("Manchester United", "MNU", "ManUtd"), ...]
for names in teams:
if team1 in names and team2 in names:
return True
return False
Output from this:
>>> equivalent("MNU", "ManUtd")
True
>>> equivalent("MNU", "Arsenal")
False
>>> equivalent("MNU", "Not a name")
False