Answer the question
In order to leave comments, you need to log in
How to make a function work properly in python?
I want to implement a function to return the position of an element in a list in python.
def index(self,item):
current = self.head
index = 0
while current != None:
if current.getData() == item : # Не могу додуматся, что нужно вставить после этого цикла
else:
current = current.getNext()
index = index + 1
return index
Answer the question
In order to leave comments, you need to log in
That's where you ask what to put in - put in reutrn index. Well, this is the case when you have found an element and you need to finish the function execution.
if current.getData() == item : # Не могу додуматся, что нужно вставить после этого цикла
return index
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question