Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

recursively and no for loops and local variable def immutify (a : 'an int , str , list, tuple, set, or dict ' ) ->

recursively and no for loops and local variable

image text in transcribed

def immutify(a : 'an int, str, list, tuple, set, or dict') -> 'an int, str, tuple, or forzenset':

IN PYTHON 3 LANGUAGE Define a recursive function named immutify; it is passed any data structure that contains int, str, tuple, list, set, frozenset, and dict values (including nested versions of any of these data structures as an argument). It returns an immutable equivalent data structure (one that could be used for values in a set or keys in a dict). The types int, str, and frozenset are already immutable. Convert a set to a frozenset; convert all the values in a tuple to be their immutable equivalents, in the same order); convert a list to a tuple (with immutable equivalents of its values, in the same order); convert a dict to tuple of 2-tuples (see the association tuple in question 2) but here with the 2-tuples sorted by the dict's keys. If immutify ever encounters a value of another type (e.g., float) it should raise a TypeError exception. The following call (with many mutable data structures) Example 1: immutify( {'b': [1,2], 'a': {'ab': {1,2}, 'aa': (1,2)}}) returns the immutable data structure (('a', (l'aa', (1, 2)), ('ab', frozenset({1, 2})))), ('b', (1, 2))) Example 2: immutify( [{1,2}, {3, frozenset([4,5])}, {6,7}]) Returns (frozenset({1, 2}), frozenset({3, frozenset({4,5})}), frozenset({6, 7}))

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, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Describe what competencies and competency modeling are.

Answered: 1 week ago