与配对一起使用更有效吗?
我有一个字典
,该字典如下:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
询问效率是没有意义的,因为
MAP
和set
做完全不同的事情。直接的问题是,您想做什么?您需要查看另一个数字所带来的数字吗?即,您是否有
“ 6”
,并且想查找并获取“ 9”
?如果是这样,请使用MAP
。您需要看看是否存在特定对?即,您是否有
(“ 6”:“ 9”)
是否是否存在?然后使用set
。关于效率,两者都将是有效的,要求他们存储它们的用途,而效率低下的人则被胁迫陷入了一些意想不到的用途。
There's no point in asking about efficiency, because a
map
and aset
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 amap
.Do you need to see if a particular pair exists? I.e., do you have
("6":"9")
and want see if it exists? Then useset
.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.