I'm a beginner with Python and wanted to make a script to collect some basketball stats from basketball-reference.com and sort the list based on a certain stat. I understand this error is thrown when you try to reference an index in a list where that index does not exist. But I've tried creating both a completely empty list and one with a defined range and I'm still getting that error.
CODE:
player_first_name = ["Luka", "Nikola", "Giannis", "Stephen", "Jayson"]
player_last_name = ["Doncic", "Jokic", "Antetokounmpo", "Curry", "Tatum"]
player = []
... some code not pertaining to this
for x in range(5):
player[x] = player_first_name[x] + " " + player_last_name[x]
NOTE: I get this error if I declare player = [], player = list(), or player = [] * 5, according to what I've read online, all of these should have been fine. The only way I can get this error to go away is if I actually put values into each index (eg. player = ["a", "b", "c", "d", "e"]
As said before, I've tried declaring the player list as:
player = []
player = [] * 5
player = list()
All of these cases resulted in the error.