与配对一起使用更有效吗?

发布于 2025-02-04 09:29:12 字数 391 浏览 4 评论 0原文

我有一个字典,该字典如下:

maps = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'}

我有一个set,如下所示:

pairs = {("0", "0"), ("1", "1"), ("6", "9"), ("8", "8"), ("9", "6")}

我了解dictionary赋予了定义键值对,但是除了与创建字典对象相比,与配对设置更有效吗?

在什么情况下,我们是否应该使用set with with with对

I have a dictionary which looks as below:

maps = {'0': '0', '1': '1', '6': '9', '8': '8', '9': '6'}

I have a set which looks as below:

pairs = {("0", "0"), ("1", "1"), ("6", "9"), ("8", "8"), ("9", "6")}

I understand that dictionary gives the ability to define key-value pairs but other than that is it more efficient to use set with pairs as compared to creating a dictionary object?

In what situation, should we use a set with pairs?

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

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

发布评论

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

评论(1

输什么也不输骨气 2025-02-11 09:29:12

询问效率是没有意义的,因为MAPset做完全不同的事情。直接的问题是,您想做什么?

您需要查看另一个数字所带来的数字吗?即,您是否有“ 6”,并且想查找并获取“ 9”?如果是这样,请使用MAP

您需要看看是否存在特定对?即,您是否有(“ 6”:“ 9”)是否是否存在?然后使用set

关于效率,两者都将是有效的,要求他们存储它们的用途,而效率低下的人则被胁迫陷入了一些意想不到的用途。

There's no point in asking about efficiency, because a map and a set do entirely different things. The immediate question is, what are you trying to do?

Do you need to see what digit goes with another digit? I.e., do you have "6", and want to look it up and get "9"? If so, use a map.

Do you need to see if a particular pair exists? I.e., do you have ("6":"9") and want see if it exists? Then use set.

In regards to efficiency, both are going to be efficient went asked to store what they are made for, and inefficient went coerced into some unintended use.

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