Merge of two ordered arrays, Python version

Source: Internet
Author: User

See the other Department of the pen Test, found that the topic: two sequential arrays of the merger, so try to write in Python

Specific as follows:

if __name__ ==  ' __main__ ':     a=[2,4,6,8,9,10]    b=[ 0,1,3,6,7,9,100,134]    counta=countb=0# record where the two arrays were traversed     c=[]     for i in range (Counta,len (a)):         for j in range (Countb,len (b)):             print  "B[j]:",j,b[j]             if (B[j]<=a[i]):                 c.append (B[j])                  countb=countb+1#append B[j], then the traversal of the B array should be self-increasing              else:                 c.append (A[i]) &NBsp;               counta=counta+1# Append A[i], then the record of the traversal of a array should be self-increasing               Why would    break# break? Because to this location, the B array can not continue to traverse down, the traversal of a      #现在就需要吧两个数组中剩余的元素依次append到c中即可     if   (Counta<len (a)):         for i in range (CountA, Len (a)):             c.append (A[i])      if  (Countb<len (b)):         for j in  range (Countb,len (b)):             c.append (b[ J])     print c


This article is from "H2O's Operation & Development Road" blog, reprint please contact the author!

Merge of two ordered arrays, Python version

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.