Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the three function in the python and use recursive 3. Write a function index(elem, seq) that takes as inputs an element elem and a

write the three function in the python and use recursive image text in transcribed
image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

Students also viewed these Databases questions

Question

Do you have sufficiently ambitious milestones?

Answered: 1 week ago

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago