Q:

Write a Python program to change Brad’s salary to 8500 in the following dictionary.

belongs to collection: Python Dictionary Exercises

1

Change value of a key in a nested dictionary

Write a Python program to change Brad’s salary to 8500 in the following dictionary.

Given:

sample_dict = {
    'emp1': {'name': 'Jhon', 'salary': 7500},
    'emp2': {'name': 'Emma', 'salary': 8000},
    'emp3': {'name': 'Brad', 'salary': 500}
}

Expected output:

{
   'emp1': {'name': 'Jhon', 'salary': 7500},
   'emp2': {'name': 'Emma', 'salary': 8000},
   'emp3': {'name': 'Brad', 'salary': 8500}
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

sample_dict = {
    'emp1': {'name': 'Jhon', 'salary': 7500},
    'emp2': {'name': 'Emma', 'salary': 8000},
    'emp3': {'name': 'Brad', 'salary': 6500}
}

sample_dict['emp3']['salary'] = 8500
print(sample_dict)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< Get the key of a minimum value from the following ...