dict1={1:"Monday",0:"Sunday",6:"Saturday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday"} sum=0 for i in dict1: sum=sum+i print(sum) dict1[7]="FUNDAY" #Adding new element or update if already exist print(dict1) dict1.update({1:"Sombaar"}) #updating value or add if not exist print(dict1) l1=list(dict1.keys()) l1.sort() dict2={x:dict1[x] for x in l1} print("Sorted: ",dict2) l2=list(dict1.values()) l2.sort() dict3={l2.index(x):x for x in l2} print(dict3) l3=list(dict1.keys()) l3.reverse() dict4={x:dict1[x] for x in l3} print(dict4)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter