Reputation: 7649
Here is an example of what I mean:
a = 0
b = 1
c = range(3)
so I would like to find the missing number in the list which in this case would be 2.
The way I have programmed it at the moment is cumbersome and ugly.
If there was a function opposite to list.append() so that I could remove values from the list instead that would be great to.
Thanks
Upvotes: 1
Views: 941
Reputation: 24044
list.remove
will remove the first occurrence of a given value from a list. If you want to specifically remove the last item (the one that was appended), use list.pop
.
Upvotes: 1
Reputation: 64147
Use set difference by converting the list to a set, then preforming the set difference operation.
>>> supplied_list = [0, 1]
>>> list(set(range(3)) - set(supplied_list))
[2]
Upvotes: 2
Reputation: 38382
Use sets:
>>> a = 0
>>> b = 1
>>> c = range(3)
>>> set(c) - set([a, b])
set([2])
Upvotes: 4