Python Algorithm Basics

Source: Internet
Author: User

1. Two-D array 90-degree rotation

data = [[col for Col in Range (4)] for row in range (4)]for v in Data:print (v) for R_index,row in Enumerate (data): for        C_index in range (R_index,len (ROW)): TMP = Data[c_index][r_index] data[c_index][r_index] = Row[c_index] Data[r_index][c_index] =tmpfor v in Data:print (v)


2. Two points Search

Def binary_search (data_source,find_n):     mid = int (len (data_source)/2)     if len (data_source)  >= 1:         if data_source[mid] > find_n:             binary_search (data_source[:mid],find_n)         elif  data_source[mid] < find_n:             binary_search (data_source[mid:],find_n)         else:             print ("Find")     else:         print ("Cannot find") if __name__ ==  ' __main __ ':     data = list (Range (1, 6000, 3))     print ( Data)      Binary_search (data,30) 



This article is from the "AMY" blog, please make sure to keep this source http://amy2015.blog.51cto.com/11407620/1769118

Python Algorithm Basics

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.