Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using python 2. Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence seq, and that uses recursion (i.e., that

image text in transcribedusing python

2. Write a function index_last(elem, seq) that takes as inputs an element elem and a sequence seq, and that uses recursion (i.e., that calls itself recursively) to find and return the index of the last occurrence of elem in seq. The sequence seq can be either a list ora 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 last(5, [4, 10, 5, 3, 7, 5]) >>> index.last('hi', C'well', 'hi', 'there']) 1 >>> index last('b, "banana) >>> index_last('n', "banana) 4 >index_last('i', 'team') 1 >>>print(index last('hi', ['hello', 111, True])) >>>print(index last('a', '")) >>>print(index_last(42, [])) # the empty string # 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

Step: 3

blur-text-image

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions