= {'a':'b', 'c':'d', 'e':'f'}
dict_data = {'c', 'e'}
set_data
swap(dict_data, set_data)print(dict_data) # {'a': 'b', 'd': 'c', 'f': 'e'}
= {23:24, 110:120, 50:45, 70:50, 57:1}
dict_data = {23, 110, 57}
set_data
swap(dict_data, set_data)print(dict_data) # {50: 45, 70: 50, 24: 23, 120: 110, 1: 57}
= {23:24, 110:120, 50:45, 70:50, 57:1}
dict_data = {100}
set_data
swap(dict_data, set_data)print(dict_data) # {23:24, 110:120, 50:45, 70:50, 57:1}
Module 14 Assignments
Programming Problems
Programming Problems should be submitted to gradescope.
Programming Problem 27
Due date: Tuesday, April 29, 2025 at 9pm
Write a Python function that does the following:
- Its name is
swap
- It takes two arguments: a dictionary and a set
- It swaps the key and value for all of the keys that exist in the dictionary that also exist in the set
- It does not return anything
Test cases:
Name the program swap_structures.py
. Make sure that gradescope gives you the points for passing the test case.
Programming Problem 28
Due date: Tuesday, April 29, 2025 at 9pm
Write a Python function that does the following:
- Its name is
get_elements
- It two arguments: a
dictionary
with strings as keys and integers as values, and an integern
- It returns a list containing all of the values who fall into at least one of these three categories:
- The corresponding key starts with an upper-case letter
- The corresponding key ends with an upper-case letter
- The value is greater than or equal to the second parameter integer
Test cases:
= {'Alpha':10, 'bravo':25, 'charliE':15, 'dELTa':2}
data print( get_elements(data, 12) ) # [10, 25, 15]
Name the program get_specific.py
. Make sure that gradescope gives you the points for passing the test case.