# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
# 1. Create an empty dictionary called dog
dog = {}
# 2. Add name, color, breed, legs, age to the dog dictionary
dog['name'] = 'Buddy'
dog['color'] = 'Brown'
dog['breed'] = 'Labrador'
dog['legs'] = 4
dog['age'] = 5
print("Dog Dictionary:", dog)
# 3. Create a student dictionary and add the required keys
student = {
'first_name': 'Nidhi',
'last_name': 'Agarwal',
'gender': 'Female',
'age': 22,
'marital_status': 'Single',
'skills': ['Python', 'SQL'],
'country': 'India',
'city': 'Mumbai',
'address': '123 Marine Drive'
}
# 4. Get the length of the student dictionary
print("Length of student dictionary:", len(student))
# 5. Get the value of skills and check the data type
skills = student['skills']
print("Skills:", skills)
print("Data type of skills:", type(skills)) # Should be a list
# 6. Modify the skills values by adding one or two skills
student['skills'].append('Machine Learning')
student['skills'].extend(['Data Analysis'])
print("Updated skills:", student['skills'])
# 7. Get the dictionary keys as a list
print("Student dictionary keys:", list(student.keys()))
# 8. Get the dictionary values as a list
print("Student dictionary values:", list(student.values()))
# 9. Change the dictionary to a list of tuples using items() method
student_items = list(student.items())
print("Student dictionary as list of tuples:", student_items)
# 10. Delete one of the items in the dictionary (e.g., marital_status)
del student['marital_status']
print("Student dictionary after deleting 'marital_status':", student)
# 11. Delete one of the dictionaries (e.g., dog)
del dog
# print(dog) # This will raise an error if you try to print it after deletion
print("Dog dictionary deleted.")