开发者

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)]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜