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]
>>>
This comment has been removed by the author.
ReplyDelete??
Deletethere is output of any question
ReplyDeleteEnter a dictionary .
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )