Given the code snippet below :
sports = ['NFL', 'MLB', 'NBA', 'NHL']
nfl_df = pd.read_csv('nfl_data.csv')
nba_df = pd.read_csv('nba_data.csv')
nhl_df = pd.read_csv('nhl_data.csv')
mlb_df = pd.read_csv('mlb_data.csv')
for sport in sports:
# For a given sport such as 'NFl', i want to access nfl_df and etc.
i know i can use if-else statements but it's really not efficient
for sport in sports :
if sport == 'NFL' :
pass
elif sport == 'NBA' :
pass
.
.
.
i know i can use dictionaries too
my_dict = {'NFL' : nfl_df, 'NBA' : nba_df, ...}
for sport in sports :
my_dict[sport] = ...
but all of these seem really non-efficient. is there any better, yet simple way to do this?