Junior — Middle
What time indicator characterizes the iteration of each element in a Python collection?
sobes.tech AI
Answer from AI
The time complexity indicator that characterizes iterating over each element in a Python collection is usually denoted as O(n), where n is the number of elements in the collection.
This means that the execution time of the iteration operation grows linearly with the increase in the size of the collection. For example, if you have a list of 100 elements, the iteration will take approximately 10 times longer than a list of 10 elements.
Example of list iteration:
my_list = [1, 2, 3, 4, 5]
for item in my_list:
print(item)
Here, the loop goes through each element once, which reflects the time complexity O(n).