Reputation: 199
What is the time complexity of this code:
if 'key' in my_dict:
print(my_dict['key'])
I just want to make sure the condition takes O(1). Is it right?
Upvotes: 0
Views: 603
Reputation: 250891
From docs:
Operation Average Case Amortized Worst Case
Get Item O(1) O(n)
x in s O(1) O(n) #From sets
Upvotes: 3