-1
def ind(e, L):
    if e not in L:
        return 0
    else:
        return 1 + ind(e, L[:1]) 
assert ind(42, [55, 77, 42, 12, 42, 100]) 

I want the index(so in this case I need 2), but the code always seems to give me the numbers instead. Also I can't use the index function in Python.

Please help if you got some time.

0

1 Answer 1

1
def ind(e, L):
    if e == L[0]:
        return 0
    else:
        return 1 + ind(e, L[1:])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.