标签: python list tuples time-complexity
tuple和list都有恒定时间O(1)来搜索元素,但每个元素的常量时间是不同的吗?
tuple
list
O(1)
我们说我有两个变量
list1 = ["hello", "how", "are", "you"] tuple1 = ("hello", "how", "are", "you")
在列表中搜索是否有不同的常量时间:
if "you" in list1: print "Found"
VS。元组:
if "you" in tuple1: print "found"