I am trying to remove a whole index in a list of lists (John in this case), as seen here where the list is called player_list:
player_list = [['Bruce Wayne', 5, 5, 0, 0, 100, 15],
['Jessica Jones', 12, 0, 6, 6, 10, 6],
['Johnny Rose', 6, 2, 0, 4, 20, 10],
['Gina Linetti', 7, 4, 0, 3, 300, 15],
['Buster Bluth', 3, 0, 2, 1, 50, 1],
['John', 0, 0, 0, 0, 100, 0]]
However, when I run the function remove_player:
def remove_player(player_list, name):
check = find_player(player_list, name)
new_list = []
if check == -1:
print(name, "is not found in players")
else:
for i in range(len(player_list)):
if player_list[i] != player_list[check]:
new_list.append(player_list[i])
player_list = new_list
print(name, "has sucessfully been removed.")
and the function: find_player:
def find_player(player_list, name):
found = -1
index = 0
while index < len(player_list) and found == -1:
if name == player_list[index][0]:
found = index
index += 1
return found
Where name comes from:
removed_player = input("Please enter name: ")
remove = remove_player(player_list, removed_player)
It does remove the index from the list, however it still is printed in the table I have created here which is not what I want it to do:
===========================================================
- Player Summary -
===========================================================
- P W L D Chips Score -
===========================================================
- Bruce Wayne 5 5 0 0 100 15 -
-----------------------------------------------------------
- Jessica Jones 12 0 6 6 10 6 -
-----------------------------------------------------------
- Johnny Rose 6 2 0 4 20 10 -
-----------------------------------------------------------
- Gina Linetti 7 4 0 3 300 15 -
-----------------------------------------------------------
- Buster Bluth 3 0 2 1 50 1 -
-----------------------------------------------------------
- John 0 0 0 0 100 0 -
-----------------------------------------------------------
===========================================================
The function I have created for the table, display_players(player_list):
def display_players(player_list):
print("===========================================================")
print("-", format("Player Summary", ">34s"), format("-", ">22s"))
print("===========================================================")
print("-", format("P", ">28s"), format("W", ">2s"), format("L", ">2s"), format("D", ">2s"), format("Chips", ">8s"), format("Score", ">8s"), format("-", ">1s"))
print("===========================================================")
for i in range(len(player_list)):
print("-", format(str(player_list[i][0]), "<25s"), format(str(player_list[i][1]), ">2s"), format(str(player_list[i][2]), ">2s"), format(str(player_list[i][3]), ">2s"), format(str(player_list[i][4]), ">2s"), format(str(player_list[i][5]), ">8s"), format(str(player_list[i][6]), ">8s"), ("-"))
print("-----------------------------------------------------------")
print("===========================================================")
I'm not sure why it is not working. Please note I am not allowed to use any of the list functions aside from list_name.append(item) in the remove_player function.
Thank you!