I
I
igoodmood2016-03-26 10:56:59
Python
igoodmood, 2016-03-26 10:56:59

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

2 answer(s)
G
GavriKos, 2016-03-26
@GavriKos

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.

A
Alexander Movchan, 2016-03-26
@Alexander1705

if current.getData() == item : # Не могу додуматся, что нужно вставить после этого цикла

Not a cycle, but conditions.
return index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question