sets in python problem
can we remove a entry from the sets.
what are the commands to use for it?
开发者_开发技巧like, my set conatins (6,5) , (6,7), (7,9)...I need to remove the second entry...what shud I do??
my_set.remove((6, 7))
The remove()
method can be used to remove items from a set.
You can use remove()
:
>>> s = set([1, 2, 3])
>>> s.remove(2)
>>> s
set([1, 3])
a -= set([(6, 7)])
:-)
If you've got a list of those tuples you can clear it out like this:
l = [(1,2),(3,4),(5,6)]
[(1, 2), (3, 4), (5, 6)]
l.remove((3,4))
[(1, 2), (5, 6)]
精彩评论