Enable the edit mode with double click on the editor.
For answers, please select the invisible text right after Answer:
Use the correct code in order to return the value associated with key 4. Do not use a method as a solution for this exercise!
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
print(value)
Output: Cardano
Answer:
value = crypto.get(3)
Use the correct code in order to update the value associated with key 3 to “Polygon”.
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
print(crypto[3])
Output: Polygon
Answer:
crypto[3] = “Polygon”
Use the correct code to return the number of key-value pairs in the dictionary.
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
number =
print(number)
Output: 5
Answer:
number = len(crypto)
Use the correct code to delete the key-value pair associated with key 4. Do not use a method as a solution for this exercise!
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
print(crypto)
Output: {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 5: "Solana"}
Answer:
del crypto[4]
Use the correct code in order to delete the key-value pair associated with key 3. This time, use a method as a solution for this exercise!
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
print(crypto)
Output: {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 5: "Solana"}
Answer:
crypto.pop(3)
Use the correct code in order to verify that 6 is not a key in the dictionary.
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
check =
print(check)
Output: True
Answer:
check = 7 not in crypto
Use the correct method in order to delete all the elements in the dictionary.
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
crypto.
print(crypto)
Output: {}
Answer:
crypto.clear()
Use the correct method in order to get a list of all the values in the dictionary.
crypto = {1: "Bitcoin", 2: "Ethereum", 3: "Cardano", 4: "XRP", 5: "Solana"}
all_list =
print(list(all_list))
Output: ["Bitcoin", "Ethereum", "Cardano", "XRP", "Solana"]
Answer:
all_list = crypto.values()