标签: python dictionary time-complexity
此代码的时间复杂度是什么:
if 'key' in my_dict: print(my_dict['key'])
我只想确保条件为O(1)。是不是?
答案 0 :(得分:3)
来自docs:
Operation Average Case Amortized Worst Case Get Item O(1) O(n) x in s O(1) O(n) #From sets