Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
How to write a function in python 3 that takes two dictionaries b1 and b2 and returns a new dictionary b3 which is the combination of b1 and b2 such that the function adds values for common keys.
Input:
b1 = {'a':1,'b':10,'c':3}
b2 = {'a':2,'b':11,'d':4}
Output:
b3 = {'a':3,'b':21,'c':3,'d':4}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Python code please help, indentation would be greatly appreciatedarrow_forwardpython exercise: Write a Python function called get_top_students that takes the list of dictionaries as input and returns a dictionary containing the name and GPA of the top two students in the list. Each dictionary has the following keys: "name", "age", "major", and "gpa".arrow_forwardNeed some help on this Python Quesionarrow_forward
- Assume a Dictionary structure has been defined that associates letter grades to their respective integer "quality point" values used for calculating a student's grade point average. The name of the structure is gradePoints. Write a statement to retrieve the quality point value for a letter grade of "C". Store the retrieved value in a variable named "qPoints".arrow_forward13. While dictionaries are designed so that we can find a value based on a key, every so often we need to perform a reverse lookup. For example, imagine a dictionary where the keys are names and the values are phone numbers. Usually we want to find the phone number based on the name, but occasionally you might need to find a name based on the phone number. Write a function called reverse_lookup(dictionary, value) that returns all the keys in the dictionary associated with the specified value. Note: In dictionaries, the keys are guaranteed to be unique, but the values are not. So your function should return a list containing all of the matching keys (if any) Example: Given this dictionary, groups = {'Apple': 'Fruit', 'Spinach': 'Vegetable', 'Banana': 'Fruit'} reverse_lookup (groups. Vegetable') ["Spinach'] reverse_lookup (groups, Fruit') ['Apple'. 'Banana'] reverse_lookup (groups. 'Meat') []arrow_forward1. Write a function invert_dict to reverse a dictionary, for example: >>> eng2sp = {'one': 'uno', 'two': 'dos', 'three': 'tres'} >>> sp2eng = invert_dict(eng2sp) >>> sp2eng {'uno':'one', 'dos':'two', 'tres':'three'} 2. Write a function print_dict to print all the key-values in a dictionary, for example: >>> d2 {'a': 'one', 'b': 'two', 'c': 'Three'} >>> print_dict(d2) a:one b:two c:Threearrow_forward
- This section has been set as optional by your instructor. OBJECTIVE: Write a program in Python that prints the middle value of a dictionary's values, using test_dict from the test_data.py module. NOTE: test_dict is created & imported from the module test_data.py into main.py Example 1: test dict = {'a':1,'b':9,'c':2,'d':5} prints 5 Example 2: test_dict = {'b':9,'d':5} prints 5 Hint: You may(or may not) find the following function useful: list.sort() which sorts the elements in a list. Note: the result is automatically stored in the original list, and return value from the function is None Туре list = [1, 2,3,2,1] After calling: list = [1,1,2,2,3] list.sort(), 339336.2266020 x3zgy7 LAB 13.11.1: Middlest Value (Structured Types) АCTIVITY 0/11 File is marked as read only Current file: test_data.py 1 #This module creates the test_dict to be used in main.py 2 #Reads input values from the user & places them into test_dict 3 dict_size = int(input()) #Stores the desired size of test_dict. 4…arrow_forwardPython Write a function that takes a string argument and returns a dictionary data structure containing the number of times each letter occurs in the string.arrow_forwardPart 3: Time for a Financial Checkup Complete the function financial_checkup, which takes a dictionary representing your monthly budget for certain categories of expenditures (budget), and a dictionary that represents how much you actually spent in each category (outlays). The function then creates and returns a new dictionary of those categories in which you overspent and the excess amount. Specifically, the returned dictionary maps the category name to the amount of excess spending, given as a negative number. If a category appears in outlays, but not budget, we interpret this to mean that we budgeted $0 for that category, so the entire amount in outlays is considered to be excess spending. Example #1: budget: spent returned: {'food' -95, 'travel': -100} Example #2: budget: spent {'food': 125, 'gas': 75, 'travel': 400} {'food' 220, 'gas': 10, 'travel': 500} Example #3: {'food' 100, 'gas': 30} {'food' 220, 'gas': 10, 'travel': 500} returned: {'food": -120, 'travel': -500} {'drinks'…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education