Python“输入"操作员速度 [英] Python "in" operator speed

查看:37
本文介绍了Python“输入"操作员速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

in 运算符在 python 中的速度是否与迭代的长度成正比?

Is the in operator's speed in python proportional to the length of the iterable?

所以,

len(x) #10
if(a in x): #lets say this takes time A
    pass

len(y) #10000
if(a in y): #lets say this takes time B
    pass

是 A > B?

推荐答案

总结:

list - Average: O(n)
set/dict - Average: O(1), Worst: O(n)

有关详细信息,请参阅.

See this for more details.

这篇关于Python“输入"操作员速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆