Python list de-bubbling sort sequencing sequencing

Source: Internet
Author: User

Python-to-list-redo example

#!/usr/bin/env PYTHONARR_NUM1 = [1,2,3,4,2,12,3,14,3,2,12,3,14,3,21,2,2,3,4111,22,3333,4]ARR_NUM2 = [ 2,1,3,2,43,234,454,452,234,14,21,14]num_list = []for i in Arr_num1:if i in arr_num2 and I not in num_list:num_list . append (i) Print num_list

Bubble Sort Example

#!/usr/bin/env pythonarr_num = [1,2,3,4,2,12,3,14,3,2,12,3,14,3,21,2,2,3,4111,22,3333,4]for  i in xrange (Len (arr_num)): For j in xrange (len (arr_num) -1-i): If arr_num[j]  > arr_num[j+1]:arr_num[j+1],arr_num[j] = arr_num[j],arr_num[j+1]print arr_num# The script execution process is as follows [1, 99, -2, 3, 14, 12, 3, -14, 3333, 4][1, -2,  99, 3, 14, 12, 3, -14, 3333, 4][1, -2, 3, 99, 14,  12, 3, -14, 3333, 4][1, -2, 3, 14, 99, 12, 3, -14,  3333, 4][1, -2, 3, 14, 12, 99, 3, -14, 3333, 4][1,  -2, 3, 14, 12, 3, 99, -14, 3333, 4][1, -2, 3, 14,  12, 3, -14, 99, 3333, 4][1, -2, 3, 14, 12, 3, -14 , 99, 3333, 4][1, -2, 3, 14, 12, 3, -14, 99, 4, 3333][-2, 1, 3,  14, 12, 3, -14, 99, 4, 3333][-2, 1, 3, 14, 12, 3,  -14, 99, 4, 3333][-2, 1, 3, 14, 12, 3, -14, 99, 4 ,  3333][-2, 1, 3, 12, 14, 3, -14, 99, 4, 3333][-2, 1,  3, 12, 3, 14, -14, 99, 4, 3333][-2, 1, 3, 12, 3,  -14, 14, 99, 4, 3333][-2, 1, 3, 12, 3, -14, 14,  99, 4, 3333][-2, 1, 3, 12, 3, -14, 14, 4, 99, 3333][-2,  1, 3, 12, 3, -14, 14, 4, 99, 3333][-2, 1, 3, 12,  3, -14, 14, 4, 99, 3333][-2, 1, 3, 12, 3, -14, 14 ,  4, 99,&Nbsp;3333][-2, 1, 3, 3, 12, -14, 14, 4, 99, 3333][-2, 1,  3, 3, -14, 12, 14, 4, 99, 3333][-2, 1, 3, 3, -14,  12, 14, 4, 99, 3333][-2, 1, 3, 3, -14, 12, 4, 14,  99, 3333][-2, 1, 3, 3, -14, 12, 4, 14, 99, 3333][-2,  1, 3, 3, -14, 12, 4, 14, 99, 3333][-2, 1, 3, 3,  -14, 12, 4, 14, 99, 3333][-2, 1, 3, -14, 3, 12, 4 , 14, 99, 3333][-2, 1, 3, -14, 3, 12, 4, 14, 99,  3333][-2, 1, 3, -14, 3, 4, 12, 14, 99, 3333][-2, 1, 3,  -14, 3, 4, 12, 14, 99, 3333][-2, 1, 3, -14, 3, 4,  12, 14,&nBsp;99, 3333][-2, 1, -14, 3, 3, 4, 12, 14, 99, 3333][-2,  1, -14, 3, 3, 4, 12, 14, 99, 3333][-2, 1, -14, 3,  3, 4, 12, 14, 99, 3333][-2, 1, -14, 3, 3, 4, 12,  14, 99, 3333][-2, -14, 1, 3, 3, 4, 12, 14, 99,  3333][-2, -14, 1, 3, 3, 4, 12, 14, 99, 3333][-2, -14, 1 ,  3, 3, 4, 12, 14, 99, 3333][-14, -2, 1, 3, 3, 4,  12, 14, 99, 3333][-14, -2, 1, 3, 3, 4, 12, 14, 99 ,  3333][-14, -2, 1, 3, 3, 4, 12, 14, 99, 3333][-14, -2,  1, 3, 3, 4, 12, 14, 99, 3333][-14, -2, 1, 3, 3,  4, 12,&nbSP;14, 99, 3333][-14, -2, 1, 3, 3, 4, 12, 14, 99, 3333] 

plug In the sort example

#!/usr/bin/env pythonarr_num = [99,1,-2,3,14,12,3,-14,3333,4]for i in xrange (1, Len (arr_num)): key = arr_num[i]j = i -1while j >= 0:if arr_num[ j] > key:arr_num[j+1] = arr_num[j]arr_num[j] = keyprint arr_numj -= The  1#print arr_num# execution process is as follows [1, 99, -2, 3, 14, 12, 3, -14, 3333,  4][1, -2, 99, 3, 14, 12, 3, -14, 3333, 4][-2, 1,  99, 3, 14, 12, 3, -14, 3333, 4][-2, 1, 3, 99, 14,  12, 3, -14, 3333, 4][-2, 1, 3, 14, 99, 12, 3, -14,  3333, 4][-2, 1, 3, 14, 12, 99, 3, -14, 3333, 4][-2,  1, 3, 12, 14, 99, 3, -14, 3333, 4][-2, 1, 3, 12,  14, 3, 99, -14, 3333, 4][-2, 1, 3, 12, 3, 14, 99, -14, 3333,  4][-2, 1, 3, 3, 12, 14, 99, -14, 3333, 4][-2, 1,  3, 3, 12, 14, -14, 99, 3333, 4][-2, 1, 3, 3, 12, - 14, 14, 99, 3333, 4][-2, 1, 3, 3, -14, 12, 14, 99,  3333, 4][-2, 1, 3, -14, 3, 12, 14, 99, 3333, 4][-2,  1, -14, 3, 3, 12, 14, 99, 3333, 4][-2, -14, 1, 3,  3, 12, 14, 99, 3333, 4][-14, -2, 1, 3, 3, 12, 14,  99, 3333, 4][-14, -2, 1, 3, 3, 12, 14, 99, 4,  3333][-14, -2, 1, 3, 3, 12, 14, 4, 99, 3333][-14, -2, 1 ,  3, 3,&nbsP;12, 4, 14, 99, 3333][-14, -2, 1, 3, 3, 4, 12, 14,  99, 3333]



This article is from the "ly36843" blog, please be sure to keep this source http://ly36843.blog.51cto.com/3120113/1710345

Python list de-bubbling sort sequencing sequencing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.