Issue
I have a list of values and I need to remove a specific one, however I end up getting the output "None", instead of a new list without the removed element
my_list = [(1, (255, 0, 255)), (10, (125, 0, 125)), (20, (0, 255, 255)), (28, (255, 0, 0)), (31, (125, 0, 255))]
new_list = my_list.remove((1, (255, 0, 255)))
print(new_list)
the output I get: None
the output I would like: [(10, (125, 0, 125)), (20, (0, 255, 255)), (28, (255, 0, 0)), (31, (125, 0, 255))]
The problem might be in the way it is formatted, however I get these results from somewhere, I didn't choose to write it like this. In that case how do I reformat the list?
Solution
remove
function modifies a list but always returns None
. You can do something like this:
my_list = [(1, (255, 0, 255)), (10, (125, 0, 125)), (20, (0, 255, 255)), (28, (255, 0, 0)), (31, (125, 0, 255))]
my_list.remove((1, (255, 0, 255)))
print(my_list)
Answered By - Ratery
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.