Answers for "how to bubble sort a 2d array in python"

-1

how to bubble sort a 2d array in python

>>> blackjackList = [['harsh', '4', 'chips'], ['ahmed', '25', 'chips'], ['yousef', '1003', 'chips'], ['krushangi', '200', 'chips'], ['bombberman', '1202', 'chips']]
>>> def quicksort(arr):
...     if len(arr)==0: return []
...     if len(arr)==1: return arr
...     left = [i for i in arr[1:] if int(i[1])<int(arr[0][1])]    # for descending, exchange
...     right = [i for i in arr[1:] if int(i[1])>=int(arr[0][1])]  # these two values
...     return quicksort(left)+[arr[0]]+quicksort(right)
...
>>> quicksort(blackjackList)
[['harsh', '4', 'chips'], ['ahmed', '25', 'chips'], ['krushangi', '200', 'chips'], ['yousef', '1003', 'chips'], ['bombberman', '1202', 'chips']]
Posted by: Guest on August-11-2020

Python Answers by Framework

Browse Popular Code Answers by Language