How do I remove only one instance from a list in Python?

John

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']
Garrett R

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I list only one instance of each comment?

How Do I Remove A Set Of Items Only Once From A List?

How to remove an instance of object from a list in python?

How do I remove 'None' items from the end of a list in Python

How do I remove escape character (\) from a list in python?

Python: How do I remove elements from a dictionary and return it as a list?

How do I remove a list of substrings from a given string in Python?

How do I remove a dictionary index from a list on Python?

How do I remove duplicate words from a list in python

How do I remove string '' from python dictionary list values?

How do I remove a index from a list of lists in Python?

How do you remove every instance of a list from another list?

How do I make sure to initialize only one Instance but from another class?

How do I compile a list from one line in python?

How do I remove only one element from an array from Redux? Not working for me currently

How do I remove commas from a list?

How do I remove duplicates based on not only one but two conditions from other columns

How do I remove the before and after arrow only from one <th></th> table?

How do I filter and remove the indexs from the List that contain only numbers?

How to remove duplicates from a list in only one method?

How to only remove one item from list with duplicates?

In mongoose, how do I remove only one document found in a collection?

How would I remove specific characters from only one column in a CSV using python?

In Python: How to remove an object from a list if it is only referenced in that list?

How do I remove a dictionary from a list depending on a value being present in a list in Python?

how do I remove an item from a list when the list is a dictionary value in Python?

How do I remove the only node in a linked list in java?

Using Python, how do I split on multiple delimiters and keep only one in my output list?

How do I return only one element from at a time and and int from range in python for loop