Untitled
unknown
plain_text
2 years ago
1.5 kB
8
Indexable
# Define the lists
keys = ['Ten', 'Twenty', 'Thirty']
values = [10, 20, 30]
# Initialize an empty dictionary
result_dict = {}
# Zip the two lists together and convert them into a dictionary
result_dict.update(zip(keys, values))
# Sort the keys alphabetically
sorted_keys = sorted(result_dict.keys())
# Print the keys and their corresponding values
for key in sorted_keys:
print(f"{key}: {result_dict[key]}")
# Define the dictionary
my_dict = {'a': 1, 'b': 2, 'c': 3}
# Insert a key in between
my_dict['new_key'] = 4
# Delete a key
if 'a' in my_dict:
del my_dict['a']
# Print the updated dictionary
print("Updated dictionary:")
print(my_dict)
# Define the dictionary
sample_dict = {'a': 100, 'b': 200, 'c': 300}
# Check if value 200 exists
if 200 in sample_dict.values():
print("Value 200 exists in the dictionary.")
else:
print("Value 200 does not exist in the dictionary.")
# Define the dictionary
sample_dict = {
"name": "Kelly",
"age": 25,
"salary": 8000,
"city": "New York"
}
# Rename the key "city" to "location"
sample_dict['location'] = sample_dict.pop('city')
# Print the updated dictionary
print("Updated dictionary:")
print(sample_dict)
# Define the dictionary
sample_dict = {
'emp1': {'name': 'Jhon', 'salary': 7500},
'emp2': {'name': 'Emma', 'salary': 8000},
'emp3': {'name': 'Brad', 'salary': 500}
}
# Change Brad's salary to 8500
sample_dict['emp3']['salary'] = 8500
# Print the updated dictionary
print("Updated dictionary:")
print(sample_dict)Editor is loading...
Leave a Comment