Algorithm of the count method in Python 3
📁 method, Advanced Python Topics
What algorithm did the developers use in the count method for strings in Python 3? What is the complexity of this algorithm?
lst = [0, 95, 0, 76, 0, 23, 68, 0, 23, 156, 95]# Since there is nothing before the first element# (including zero, which satisfies the condition),# it is added in any case.# Also when i == 0, i - 1 == -1 will not cause an exception,# because the element with index -1 exists in the list,# it is the last element of the list# Using a loopnew_list = []
Log in to leave an answer