how to bubble sort a 2d array in python

Solutions on MaxInterview for how to bubble sort a 2d array in python by the best coders in the world

showing results for - "how to bubble sort a 2d array in python"
Fabio
02 Jan 2018
1>>> blackjackList = [['harsh', '4', 'chips'], ['ahmed', '25', 'chips'], ['yousef', '1003', 'chips'], ['krushangi', '200', 'chips'], ['bombberman', '1202', 'chips']]
2>>> def quicksort(arr):
3...     if len(arr)==0: return []
4...     if len(arr)==1: return arr
5...     left = [i for i in arr[1:] if int(i[1])<int(arr[0][1])]    # for descending, exchange
6...     right = [i for i in arr[1:] if int(i[1])>=int(arr[0][1])]  # these two values
7...     return quicksort(left)+[arr[0]]+quicksort(right)
8...
9>>> quicksort(blackjackList)
10[['harsh', '4', 'chips'], ['ahmed', '25', 'chips'], ['krushangi', '200', 'chips'], ['yousef', '1003', 'chips'], ['bombberman', '1202', 'chips']]