Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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']]
Comment

PREVIOUS NEXT
Code Example
Python :: printing in python 
Python :: python numpy euler 
Python :: Following Links in Python 
Python :: rezise object pygame 
Python :: I**2 python 
Python :: Get git sha 
Python :: one line try except python 
Python :: inverse matrix gauss python 
Python :: random module 
Python :: how to use visualize_runtimes 
Python :: loading .dat file in python 
Python :: python returning rows and columns from a matrix string 
Python :: elavon converge api python tutorial 
Python :: pss signatures python 
Python :: python replace list of ips from yaml file with new list 
Python :: flatten a list of lists python 
Shell :: how to check laptop serial number in ubuntu 
Shell :: bash: netstat: command not found 
Shell :: git update gitignore 
Shell :: git stash untracked files 
Shell :: git set email and username 
Shell :: chrome update ubuntu 20.04 
Shell :: how to update git submodule 
Shell :: ubuntu tweak 
Shell :: kill the port in mac 
Shell :: ubuntu install vlc 
Shell :: install beautifulsoup windows 
Shell :: remove oh my zsh ubuntu 
Shell :: ubuntu install okular 
Shell :: docker-compose install centos 8 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =