Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

could u help me this playlist question def invert_and_sort(key_to_value: Dict[object, object]) -> Dict[object, list]: Return key_to_value inverted so that each key is a value (for

could u help me this playlist question

image text in transcribedimage text in transcribedimage text in transcribed
def invert_and_sort(key_to_value: Dict[object, object]) -> Dict[object, list]: """Return key_to_value inverted so that each key is a value (for non-list values) or an item from an iterable value, and each value is a list of the corresponding keys from key_to_value. The value lists in the returned dict are sorted. >>> invert_and_sort(P2C) == { 'Comet Club' : ['Michelle Tanner' ], 'Parent Council' : ['Danny R Tanner' , 'Jesse Katsopolis' , 'Joey Gladstone' ], Rock N Rollers': ['Jesse Katsopolis' , 'Kimmy Gibbler'], 'Comics R Us' : ['Joey Gladstone' ], 'Smash Club' : ['Kimmy Gibbler' ]} True 11 11 11 result = {} for key in key_to_value: for item in key_to_value [key] : if item in result: result[item] . append(key) else: result[item] = for i in result: result[item] . append(key) result[i] = sorted(list(set(result[i]))) return resultfrom typing import List, Tuple, Dict, TextIO # Sample Data (Used by Doctringales) P2F = {'Jesse Katsopolis' : ['Danny R Tanner' , 'Joey Gladstone' , 'Rebecca Donaldson-Katsopolis' ], 'Rebecca Donaldson-Katsopolis' : ['Kimmy Gibbler'], 'Stephanie J Tanner' : ['Michelle Tanner' , 'Kimmy Gibbler' ], 'Danny R Tanner' : ['Jesse Katsopolis', 'DJ Tanner-Fuller', 'Joey Gladstone' ]} P2C = {'Michelle Tanner' : ['Comet Club'], 'Danny R Tanner' : ['Parent Council' ], 'Kimmy Gibbler' : ['Rock N Rollers' , 'Smash Club'], 'Jesse Katsopolis' : ['Parent Council' , 'Rock N Rollers' ], 'Joey Gladstone' : ['Comics R Us' , 'Parent Council']} # Helper functions def update_dict(key: str, value: str, key_to_values: Dict[str, List[str]]) -> None: if key not in key_to_values: key_to_values[key] = if value not in key_to_values[key] : key_to_values[key] . append(value)The parameter represents a dictionary, in which either the value are all lists or none of the values are lists. This function must return a new dictionary that is the given dictionary inverted: eac key is a value or an item from a values list from the given dictionary, and each value is a list of the corresponding keys from the given dictionary. The items in the new dictionary's values list are sorted. For example, given the following argument (based on profiles. txt ): {'Claire Dunphy': ['Parent Teacher Association'], 'Manny Delgado' : ['Chess Club'], invert_and_sort : 'Mitchell Pritchett': ['Law Association' ], (Dict [object, object]) - 'Alex Dunphy' : ['Chess Club', 'Orchestra'], 'Cameron Tucker' : ['Clown School', 'Wizard of Oz Fan Clu > Dict[object, list] b' ] , 'Phil Dunphy' : ['Real Estate Association'], Gloria Pritchett' : ['Parent Teacher Association' ]} the function should return: {'Parent Teacher Association': ['Claire Dunphy', 'Gloria Pri tchett' ], 'Chess Club' : ['Alex Dunphy', 'Manny Delgado' ], ' Law Association': ['Mitchell Pritchett' ], 'Orchestra' : ['Alex Dunphy' ], 'Clown School' : ['Cameron Tucker'], 'Wizard of Oz Fan Club' : ['Cameron Tucker' ], 'Real Estate Association': ['Phil Dunphy' ]}

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

Students also viewed these Programming questions