Thursday, April 25, 2019

python - How to remove a specific object in a list?




For example I have a list that looks like this:



l = [(1,2),(1,3),(4,1)]



how can I remove item (1,3) without knowing the index of the item?



I tried l.pop((1,3)) but I got this error message: TypeError: an integer is required


Answer



l = [(1,2),(1,3),(4,1)]
print(l) #[(1, 2), (1, 3), (4, 1)]
l.remove((1,3))
print(l) #[(1, 2), (4, 1)]


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...