Question: using recursion to create function in python 3. Write a function index(elem, seq) that takes as inputs an element elem and a sequence seq, and

 using recursion to create function in python 3. Write a function
index(elem, seq) that takes as inputs an element elem and a sequence
seq, and that uses recursion to find and return the index ofusing recursion to create function in python

3. Write a function index(elem, seq) that takes as inputs an element elem and a sequence seq, and that uses recursion to find and return the index of the first occurrence of elem in seq. The sequence seq can be either a list or a string. If seq is a string, elem will be a single-character string; if seq is a list, elem can be any value. Don't forget that the index of the first element in a sequence is 0 Important notes: If elem is not an element of seq, the function should return-1. You may not use the in operator in this function. Here are some examples: >index(5, [4, 10, 5, 3, 7, 5]) >index('hi', ['we11', 'hi', 'there']) 1 >index(b 'banana) 0 >index('a 'banana) 1 indexC'i', 'team' 1 >printCindex('hi ['hel1o', 111, True])) 1 printCindex('a', ")) 1 # the empty string >print (index (42, [])) # the empty list 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!