This article illustrates the application of Python fast lookup algorithm, and share it for everyone's reference.
The implementation methods are as follows:
Import Random
def partition (list_object,start,end):
random_choice = Start
#random. Choice (Start, end+1)
#把这里的start改成random () efficiency will be higher
x = list_object[random_choice]
i = start
j = End While
True: While
List_object[i] < x and I < end:
i + 1 while
list_object[j] > x:
J-= 1
If I >= J:
break
list_object[i],list_object[j] = list_object[j],list_object[i]
print List_object
# List_object[random_choice] = list_object[j]
#list_object [j] = Random_choice return
J
def Quick_sort ( List_object,start,end):
If start < end:
temp = partition (list_object,start,end)
Quick_sort (list_ object,start,temp-1)
Quick_sort (list_object,temp + 1, end)
a_list = [69,65,90,37,92,6,28,54]
Quick_ Sort (a_list,0,7)
print a_list
Program test environment for Python2.7.6
The output results are as follows:
[Si, 6, mb
, M, [6, Panax Notoginseng
, Si, the [6, Panax Notoginseng
, Si, the [6, Panax Notoginseng, si,
the [6, Panax Notoginseng, si,
the [6, 28, 37, 54, 65, 69, 90, 92]
I hope this article will help you with your Python programming.