Question

(Python) assume the variable dct references a dictionary. Write an if statement that determines whether the...

(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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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']

Add a comment
Know the answer?
Add Answer to:
(Python) assume the variable dct references a dictionary. Write an if statement that determines whether the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The variable most_recent_novel is associated with a dictionary that maps the names of novelists to their...

    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...

    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'...

    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...

    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...

    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....

    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...

    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...

    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,...

    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...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT