Question

In: Computer Science

In Python: Create a dictionary of at least 5 key/value pairs. Add a new key/value pair...

In Python:

  1. Create a dictionary of at least 5 key/value pairs.
  2. Add a new key/value pair to the dictionary.
  3. Change one of the values through reassignment.
  4. Access at least 3 values using the keys.
  5. Access at least 3 keys using the values.
  6. Delete an element.
  7. Test for key inclusion for 3 elements.
  8. Loop through the dictionary, printing out the key and value on the same line separated by a space.

Key1, value1

Key2, value2

…,     …

(Please if you can, provide screenshots)

Thank YOU!

Solutions

Expert Solution

I put the code in python as your requirements. please go through code, also putting the screenshot of output of the code and if you have any doubt, feel free to comment down and if you like, please give me upvote.
mydict = {
  "fruit1": "Banana",
  "fruit2": "Apple",
  "Car1": "BMW",
  "Car2": "OD",
  "Car3": "Toyota",
  "Vegetable1": "Tomato"
}

# Adding a new key with value
mydict["Added_Vegetable"] = "Potato_added"

# Reassignment of one key
mydict["fruit1"] = "Banana_Updated"

# deleting Key Car2, so it will not be there in final list
del mydict["Car2"] 

# Inclusion of Key:

print("\nInclusion:  \n")
print("'fruit1' key is there or not ?")
print('fruit1' in mydict)

print("'fruit9' key is there or not ?")
print('fruit9' in mydict)

print("'Added_Vegetable' key is there or not ?")
print('Added_Vegetable' in mydict)

print("\nValue from key: ")
# Find value on key
print(mydict["fruit1"])
print(mydict["Car1"])
print(mydict["Added_Vegetable"])

# key list
key_list = list(mydict.keys()) 
# Value list
val_list = list(mydict.values())


print('\nKey from Values: ')
print(key_list[val_list.index("Apple")]) 
print(key_list[val_list.index("Toyota")]) 
print(key_list[val_list.index("Banana_Updated")])


print("\nDictionary: ")
for key in mydict:
        print(key, mydict[key])


Related Solutions

In Perl: Create a dictionary of at least 5 key/value pairs. Add a new key/value pair...
In Perl: Create a dictionary of at least 5 key/value pairs. Add a new key/value pair to the dictionary. Change one of the values through reassignment. Access at least 3 values using the keys. Access at least 3 keys using the values. Delete an element. Test for key inclusion for 3 elements. Loop through the dictionary, printing out the key and value on the same line separated by a space. Key1, value1 Key2, value2 …,     … (Please if you...
Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
Python - Create/Initialize a dictionary with 5 state/capital pairs of your choosing. The state is the...
Python - Create/Initialize a dictionary with 5 state/capital pairs of your choosing. The state is the key and the capital is the value (e.g. “Kansas”:”Topeka”). Only one statement is needed to do this. - Then prompt the user for a state. e.g. The output Enter a state, and I will display the capital. State: Colorado Colorado's capital is Denver. - If that state exists in the dictionary, display the capital, else display "I'm sorry, but I still need to record...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
Using python. 1. How to create a dictionary that has an integer as a key and...
Using python. 1. How to create a dictionary that has an integer as a key and a byte as a value? the dictionary keys must contain integers from 0 to 255. It should be similar to UTF-8. When we enter an integer, it should return 1 byte. 2. Create a function when a user gives 1 byte, it should return the key from the previous dictionary.
I have a python dictionary with the following format Key Type Value January str ['January 01...
I have a python dictionary with the following format Key Type Value January str ['January 01 2020', 'January 02 2019', 'January 03 2018'] June str ['June 04 2018', 'June 05 2018', 'June 06 2016] August str ['Augsut 07 2016', 'August 08 2016'] How do return the following conclusion with python code? January has the most day (1) in 2020 January has the most day (1) in 2019 June has the most days (2) in 2018 August has the most days...
Use a dictionary to represent a directed graph in which each key is a pair (tuple)...
Use a dictionary to represent a directed graph in which each key is a pair (tuple) of two nodes, with the corresponding value set to the edge weight. For example, W[u,v] =42. Where in u → v. Write a function to calculate the in and out degree of a given node. What would be the advantages and disadvantages of this representation? in python
Process each line so you create dictionary where key is name of the company and value...
Process each line so you create dictionary where key is name of the company and value is a net balance #2.a. First column of each row is a name of the company #2.a.a. Utes company has different types of spelling, so you need to put all of them under the same key #2.b. Second column is payments in #2.c. Third column is payments out. Note that they can be negatives as well. # Hint: Absolute value could be derived by...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names to addresses. A person's name (stored as a string) will be the KEY and that person's address (stored as a string) will be the VALUE. 1.2) Insert into the dictionary 'addresses' the names and addresses of two (possibly imaginary) friends of yours. 1.3) Create a second empty dictionary called 'ages'. The dictionary you just created will map names to ages. A person's name (stored...
Create two functions that you can use for a dictionary manager: 1. remove_item(dictionary,key): a function that...
Create two functions that you can use for a dictionary manager: 1. remove_item(dictionary,key): a function that removes the item with the supplied key from the dictionary, if it exits. If the input key doesn’t exist in the dictionary, print out a message saying that the new item has not been removed because there is no matching key in the dictionary. Your function should not produce a Python error if the item does not exist; 2. add_new_item(dictionary,key,value): a function that adds...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT