(Python)
assume the variable dct references a dictionary. Write an if statement that determines whether the key 'Jon' exists in the dictionary. If so, assign the value 'Jon' to a key of 'John', and then delete 'Jon' and its associated value.
assume the variable dct references a dictionary.
An if statement that determines whether the key 'Jon' exists in the dictionary.
If so, assign the value 'Jon' to a key of 'John', and then delete 'Jon' and its associated value.
if 'Jon' in dct.keys():
dct['John'] = dct['Jon']
del dct['Jon']

(Python) assume the variable dct references a dictionary. Write an if statement that determines whether the...
For Python 3 MPLS please 1. Given a variable, unproved_conjectures, that is associated with a dictionary that maps the common names of mathematical conjectures to the years when the conjectures were made, write a statement that deletes the entry for "Fermat's Last Theorem". 2. Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of the new dictionary and the values of d become the keys...
The variable most_recent_novel is associated with a dictionary that maps the names of novelists to their most recently published novels. Write a statement that replaces the value "Harry Potter and the Half-Blood Prince" with the value "Harry Potter and the Deathly Hallows" for the key "J.K. Rawling". In Python
Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this dictionary each key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course. For example, the following...
Write a statement that creates a dictionary containing the following key-value pairs: 'a' : 1 'b' : 2 'c' : 3 python!
Write the function, toppings, that takes a dictionary and modifies it as follows: If the key "potato" has a value, set that as the value for the key "fries". If the key "salad" has a value, set that as the value for the key "spinach". the starter code is listed bellow do not change the code complete in Python def toppings(dictionary): #Your code here pass #placeholder statement - delete when you have actual code here #testing code dict1 = {'potato':...
Python: Write an inline if statement to assign x the value 1 if the variable y = 'female' and assign x the value 0 if the variable y = 'male'. The variable y has only two possible values, 'male' and 'female'.
Python 3 Write a function named starCounter that takes three parameters: 1. a dictionary named starDictionary. Each key in starDictionary is the name of a star (a string). Its value is a dictionary with two keys: the string 'distance' and the string 'type'. The value associated with key 'distance' is the distance from our solar system in light years. The value associated with key 'type' is a classification such as 'supergiant' or 'dwarf'. 2. a number, maxDistance 3. a string,...
PYTHON 3: Write a function removeRand() that takes a dictionary d and an integer n as parameters. The function randomly chooses n key-value pairs and removes them from the dictionary d. If n is greater than the number of elements in the dictionary, the function prints a message but does not make any changes to d. If n is equal to the number of elements in d, the function clears the dictionary. Otherwise the function goes through n rounds in...
PYTHON PROGRAM
by using functions & dictionary or set.
- must create a variable to hold a dictionary or sets
- must define a function that accepts dictionaries or sets as an
argument
A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. For e.g.: a dictionary defined as: released = { "iphone" : 2007, "iphone 3G": 2008, "iphone 3GS": 2009, "iphone 4" : 2010,...
s1 = 'Practice How to Use String Object' Write a python statement that splits the string, creating the following list: ['Practice', 'How', 'to', 'Use', 'String', 'Object'] 2. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’: reply = input("Y or y to continue: ") if reply == "Y" and reply == "y": print("Y --- <uppercase> has been selected. ") else: print("y --- <lowercase> has been chosen. ") print("… continue...