import operator
d={'oil':230,'clip':150,'nut':175,'needle':35}
print(" Original Dictionary : ",d)
d1=sorted(d.items())
print("Ascending order by key : ",d1)
d2=sorted(d.items(),reverse=True)
print("Descending order by key : ",d2)
d1=sorted(d.items(),key=operator.itemgetter(1))
print("Ascending order by value :",d1)
d2=sorted(d.items(),key=operator.itemgetter(1),reverse=True)
print("Descending order by value :",d2)
0 Comments