I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Delete set of keys from Python Dictionary
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#Delete set of keys from Python Dictionary
#initializing Dictionary
sampleDict = {
"name": "Kelly",
"age":25,
"salary": 8000,
"city": "New york"
}
#keys to remove
keysToRemove = ["name", "salary"]
#for loop will iterate 2 times because keysToRemove has 2
elements
#for every iteration, one value from keysToRemove is assigned to
i
for i in keysToRemove:
#if that i value is in sampleDict
if i in sampleDict:
#Delete the value
del sampleDict[i]
#printing the sampleDict
print(sampleDict)
//code ended here
Output:
Iterate over dictionaries using for loops
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#Iterate over dictionaries using for loops
#Initializing Dictionary
d = {'x':1, 'y':2, 'z':3}
#for loop will iterate 3 times because 3 items in d
#for every iteration, one key and one value is assigned to
key,value
#sorted is used to sorts the items in an order
for key,value in sorted(d.items()):
#printing key and value
print(key,"->",value)
//code ended here
Output:
get maximum and minimum values in a Dictionary
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#get maximum and minimum values in a Dictionary
my_dict = {'x':500, 'y':5874, 'z':560}
#taking values to val
val = my_dict.values()
#finding Maximum value in it
maximum = max(val)
#finding Minimum value in it
minimum = min(val)
#printing Maximum and Minimum value
print("Maximum value: ",maximum)
print("Minimum value: ",minimum)
//code ended here
Output:
change Brad's salary to 8500
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#change Brad's salary to 8500
#initializing Dictionary
sampleDict = {
'emp1': {'name': 'Jhon', 'salary': 7500},
'emp2': {'name': 'Emma', 'salary': 8000},
'emp3': {'name': 'Brad', 'salary': 6500}
}
#changing salary to 8500
sampleDict['emp3']['salary'] = 8500
#printing sampleDict
print(sampleDict)
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!
they are 2 pictures attached 4) Delete set of keys from Python Dictionary Given: sampleDict =...
Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is MyDict = { 1: 'One', 2: 'Two', 3: 'Three' } Then ( 2 in MyDict.keys() ) evaluates to True, indicating that 2 is a valid key for MyDict....
PYTHON Text file Seriesworld attached below and it is a list of teams that won from 1903-2018. First time mentioned won in 1903 and last team mentioned won in 2018. World series wasn’t played in 1904 and 1994 and the file has entries that shows it. Write a python program which will read this file and create 2 dictionaries. The first key of the dictionary should show name of the teams and each keys value that is associated is the...