| 
 | 1 | +### Bubble Sort Exercise  | 
 | 2 | + | 
 | 3 | +Modify [merge_sort function](https://github.com/codebasics/py/blob/master/Algorithms/5_MergeSort/merge_sort.py) such that it can sort following list of athletes as per the time taken by them in the marathon,  | 
 | 4 | +```  | 
 | 5 | +elements = [  | 
 | 6 | +        { 'name': 'vedanth',   'age': 17, 'time_hours': 1},  | 
 | 7 | +        { 'name': 'rajab', 'age': 12,  'time_hours': 3},  | 
 | 8 | +        { 'name': 'vignesh',  'age': 21,  'time_hours': 2.5},  | 
 | 9 | +        { 'name': 'chinmay',  'age': 24,  'time_hours': 1.5},  | 
 | 10 | +    ]  | 
 | 11 | +```   | 
 | 12 | +merge_sort function should take key from an athlete's marathon log and sort the list as per that key. For example,  | 
 | 13 | +```  | 
 | 14 | +merge_sort(elements, key='time_hours', descending=True)  | 
 | 15 | +```  | 
 | 16 | +This will sort elements by time_hours and your sorted list will look like,  | 
 | 17 | +```  | 
 | 18 | +elements = [  | 
 | 19 | +        {'name': 'rajab', 'age': 12, 'time_hours': 3},  | 
 | 20 | +        {'name': 'vignesh', 'age': 21, 'time_hours': 2.5},  | 
 | 21 | +        {'name': 'chinmay', 'age': 24, 'time_hours': 1.5},  | 
 | 22 | +        {'name': 'vedanth', 'age': 17, 'time_hours': 1},  | 
 | 23 | +    ]  | 
 | 24 | +```   | 
 | 25 | +But if you call it like this,  | 
 | 26 | +```  | 
 | 27 | +merge_sort(elements, key='name')  | 
 | 28 | +```  | 
 | 29 | +output will be,  | 
 | 30 | +```  | 
 | 31 | +elements = [  | 
 | 32 | +        { 'name': 'chinmay',   'age': 24, 'time_hours': 1.5},  | 
 | 33 | +        { 'name': 'rajab', 'age': 12,  'time_hours': 3},  | 
 | 34 | +        { 'name': 'vedanth',  'age': 17,  'time_hours': 1},  | 
 | 35 | +        { 'name': 'vignesh',  'age': 21,  'time_hours': 2.5},  | 
 | 36 | +    ]  | 
 | 37 | +```   | 
 | 38 | + | 
 | 39 | +[Solution](https://github.com/codebasics/py/blob/master/Algorithms/2_BubbleSort/merge_sort_exercise_solution.py)  | 
 | 40 | + | 
0 commit comments