Answers for "python list index time complexity"

1

python list index time complexity

lst = ["Alice","Bob","Duckie","Toucan"]
lst.index("Toucan")
3
The index function returns where the value given is in the string. 
The time complexity is O(n), as the worst case scenario requires iterating 
over n elements to find the desired result.
Posted by: Guest on August-16-2021

Code answers related to "python list index time complexity"

Python Answers by Framework

Browse Popular Code Answers by Language