Q.No.1 - Write a Python program to Sort Python Dictionaries by Key or Value.

Sol.-

dicta={"zeta":10,"meta":100,"hexa":50,"axe":15,"beta":20}
dictkeys=list(dicta.keys())
dictkeys.sort()
sorted_dict={i:dicta[i] for i in dictkeys}
print("Dictionary sort by keys :",sorted_dict)
dictvalue= list(dicta.values())
dictvalue.sort()
sort_dict_by_value={}
for i in dictvalue:
    for k in dictkeys:
        if i==dicta[k]:
            sort_dict_by_value[k]=dicta[k]
print("Dictionary sort by values :",sort_dict_by_value)



Explain :
Step 1: Here we create a dictionary name - dicta.
Step 2: We convert dictionary keys in list.
Step 3: Use sort function of list and sort dictionary keys.
Step 4: Create a variable ( sorted_dict ) and use for loop so it get sorted key and then there value.
Step 5: Print that sorted key dictionary.
Step 6: Again Create a variable dictvalue in which dictionary values store.
Step 7: Sort these values.
Step 8: Create a empty dictionary ( sort_dict_by_value ).
Step 9: Use loop 
Step 10: Print the dictionary (sort_dict_by_value) in which sort on basis of values.

OUTPUT: