Thursday 25 April 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...