Q. Write a program to sort a dictionary’s value using bubble sort and produce the sorted values as a list.


You can understand by Watching video :-



Answer =

dic = eval (input("Enter a dictionary : "))
val = list(dic.values())

for i in range ( len ( val ) - 1 ) :
    if  val [ i ] > val [ i + 1 ] :
        val [ i ] , val [ i + 1 ] =  val [ i + 1 ] , val [ i ]
        
print(val)

Output :-

Enter a dictionary : {"Path":5,"Walla":3,"Portal":4,"Express":7}
[3, 4, 5, 7]
>>>

Enter a dictionary : {"Python":9,"C++":2,"Java":7,"CSS":3}
[2, 7, 3, 9]

>>> 


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post