Python Write a function revers_all (sequence) that takes an arbitrary nested list sequence with arbitrary elements and returns a new list that has the same nested structure, but where all lists both at the top level and at all nested levels are reserved ("backwards") example reverse_all ([1, 2, 3, [4, 5, ['x', 7]], 8]) becomes [8, [[7, 'x'], 5, 4], 3, 2, 1] I sent parameters can not be changed. It is thus a completely new list to be returned. It is allowed to solve the task recursively or itrelatively or with a compilation of these methods. Your function may not make any readings or printouts Use this program to test import copy   sequence = eval(input()) seq_copy = copy.deepcopy(sequence) result = reverse_all(sequence) print (result) if results is sequence:          print("Your function does not create a new list") if sequence != seq_copy:          print("Your function changes in that submission list")

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python

Write a function revers_all (sequence) that takes an arbitrary nested list sequence with arbitrary elements and returns a new list that has the same nested structure, but where all lists both at the top level and at all nested levels are reserved ("backwards")

example
reverse_all ([1, 2, 3, [4, 5, ['x', 7]], 8]) becomes
[8, [[7, 'x'], 5, 4], 3, 2, 1]

I sent parameters can not be changed. It is thus a completely new list to be returned.
It is allowed to solve the task recursively or itrelatively or with a compilation of these methods. Your function may not make any readings or printouts

Use this program to test

import copy
 
sequence = eval(input())
seq_copy = copy.deepcopy(sequence)
result = reverse_all(sequence)
print (result)
if results is sequence:
         print("Your function does not create a new list")
if sequence != seq_copy:
         print("Your function changes in that submission list")
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education