(PP-4)
4A.Write a python program to sort a dictionary.
dict1={'number':123,'name':'roman','country':'india'}
a=sorted(dict1.items())
print(a)
or
dict1={'number':123,'name':'roman','country':'india'}
for key,value in sorted(dict1.items()):
print(key,value)
print(sorted(dict1))
4B.write a python program to concatenate two dictionaries and create a new one.
4D.Write
a python program to add a new key-value
pair to dictionary.
dict1={'name':'AJ','age':19}
dict1['Rollno']=1
print(dict1)
4E.Write python program to check if given key exists in a dictionary or not
def checkkey(dict,key):
if key in dict.keys():
print("present")
else:
print("not present")
dict={'a':100,'b':200,'c':300}
key='c'
checkkey(dict,key)
4F.Write a python program
to multiply the items in dictionary
d={'a':10,'b':20,'c':30}
def multiply(d):
multiply=1
for i in d.values():
multiply*=i
return multiply
print(multiply(d))
4G.Write a
python program to remove a given key value pair from the dictionary.
Comments
Post a Comment