(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.

dict1={'name':'manju'}
dict2={'age':19}
dict1.update(dict2)
print(dict1)

        for 3
dict1={'name':'manju'}
dict2={'age':19}
dict3={'address':'amroli'}
dict1.update(dict2)
dict1.update(dict3)
print(dict1)

4C. Write a Python program to sum all the items in a dictionary.

d= {'One':10,'Two':20,'Three':30}
sum(d.values())

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.

d={'a':10,'b':20,'c':30}
del d['a']
print(d)



       






Comments

Popular posts from this blog

python(BI)

Prac_8(AMP)

LSA10