Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question-2: Here, each odd and even keys of the dictionary carry a tuple of names and a tuple of numbers respectively. Your task is to

Question-2: Here, each odd and even keys of the dictionary carry a tuple of names and a tuple of numbers respectively. Your task is to write a python program to generate the following output dictionary below so that the names (keys of the output dictionary) are sorted in descending order based on the sum of their ASCII values and the numbers corresponding to each name (values of the output dictionary) are generated by summing the ASCII values of the key with a single number from the sorted number list generated from the numbers available in the tuples of the input dictionary. ================================================ GIVEN dictionary1: dict1={1: ("Leo", "Kim", "Joe", "Brad"), 2:(12, 15, 10, 14), 3: ("Joey", "Tim", "Jen", "Jack"), 4:(19, 13, 17, 11)} Sample Output 1: {'Joey': 417, 'Brad': 388, 'Jack': 389, 'Tim': 311, 'Kim': 303, 'Leo': 303, 'Joe': 303, 'Jen': 304} Explanation1: In the output dictionary, for example, the ASCII value sum of Joey is 407, which is larger than the rest of the names and thats why it is at the beginning of the dictionary. Now, the sorted list of the numbers available in the tuples of the input dictionary is: [10, 11, 12, 13, 14, 15, 17, 19] So, the final value of Joey is = 407+10=417 For, Brad, the sum of the ASCII value is= 377 So, the final value of Brad is= 377+11=388 The rest of the dictionary is made following this pattern. ================================================ GIVEN dictionary2: dict1= {1:("Brad","Liam","Corey"), 2:(15,25,100), 3:("Tom","Jessy"), 4:(21,33)} Sample Output2: {'Jessy': 541, 'Corey': 535, 'Liam': 412, 'Brad': 410, 'Tom': 404} Explanation2: In the output dictionary, for example, the ASCII value sum of Jessy is 526, which is larger than the rest of the names and thats why it is at the beginning of the dictionary. Now, the sorted list of the numbers available in the tuples of the input dictionary is: [15, 21, 25, 33, 100] So, the final value of Jessy is = 526+15=541 For, Corey, the sum of the ASCII value is= 514 So, the final value of Corey is= 514+21=535 The rest of the dictionary is made following this pattern.

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