python 中的集合问题

发布于 2024-09-09 17:25:18 字数 99 浏览 1 评论 0原文

我们可以从集合中删除一个条目吗?

使用什么命令?

就像,我的设置包含 (6,5) 、(6,7)、(7,9) ...我需要删除第二个条目...我该做什么?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天荒地未老 2024-09-16 17:25:18
my_set.remove((6, 7))

remove() 方法可用于从集合中删除项目。

my_set.remove((6, 7))

The remove() method can be used to remove items from a set.

病女 2024-09-16 17:25:18

您可以使用 remove()

>>> s = set([1, 2, 3])
>>> s.remove(2)
>>> s
set([1, 3])

You can use remove():

>>> s = set([1, 2, 3])
>>> s.remove(2)
>>> s
set([1, 3])
ぇ气 2024-09-16 17:25:18

a -= 设置([(6, 7)])

:-)

a -= set([(6, 7)])

:-)

别挽留 2024-09-16 17:25:18

如果您有这些元组的列表,您可以像这样清除它:

l = [(1,2),(3,4),(5,6)]

[(1, 2), (3, 4), (5, 6)]
l.remove((3,4))
[(1, 2), (5, 6)]

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)]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文