Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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. Dont 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started