Question
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.
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. intStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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