So I have a Python script that reads in a .csv file of a play-by-play of a basketball game to calculate a plus/minus by lineup. It keeps track of the current players on the floor in a list of the player's last names, and I encounter an error when a team has two players with the same last name (the play-by-play data doesn't use first names, only numbers and last names, and I don't keep track of their numbers). The problem comes when I use lineup.remove(player) on one of the duplicate names, it removes both from the list. Is there an easy way to only remove one, and if so, can I specify which?
Example list would be
['JONES', 'PATTERSON', 'SMITH', 'JONES', 'WILLIAMS']
From the docs:
list.remove(x) Remove the first item from the list whose value is x. It is an error if there is no such item.
lineup = ['JONES', 'PATTERSON', 'SMITH', 'JONES', 'WILLIAMS']
lineup.remove('JONES') #should just remove the first occurrence of JONES
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With