Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON 3 LANGUAGE Define a recursive function named my_str; it is passed an int or list whose elements are ints or lists of ints,

IN PYTHON 3 LANGUAGE

Define a recursive function named my_str; it is passed an int or list whose elements are ints or lists of ints, or lists of lists of ints, etc. It returns a string: the same string that str returns when called on such an argument (but, of course, you cannot call str or __str__ etc. You must write your own recursive my_str function that solves this problem). my_str must deal with references inside the list that refer to the list. For example, if we wrote x = [1,1] and then x[1] = x the following structure results.

image text in transcribed

Sample output:

x = [1,[2],3]

x[1] = x

my_str(x) == str(x) #returns '[1, [...], 3]'

x = [1,2,3]

x[1] = x

y = [10,11,12]

x[0] = y

y[2] = x

my_str(x)==str(x) #returns '[[10, 11, [...]], [...], 3]'

my_str(y)==str(y) #returns '[10, 11, [[...], [...], 3]]'

list str (x) returns [1, [...11; my str(x) should return the same. In a recursive call, when asked to convert a list that is already being converted immediately return [...1. int

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

More Books

Students also viewed these Databases questions

Question

Identify the different methods employed in the selection process.

Answered: 1 week ago

Question

Demonstrate the difference between ability and personality tests.

Answered: 1 week ago