Python quick release

Source: Internet
Author: User


Differences:
The Perl transfer list slice actually points to the same element in the parent list, which is determined by the data structure of Perl. While passing slice in Python is a new list, so parameter passing is slightly different.

An example shows the differences in parameters passing through Perl:
[Plain] view plaincopy
Sub test {
$ _ [2] = 'testing ';
}
 
@ X = (1 .. 10 );
Test (@ x [3 .. 8]);
Print "@ x ";
 
Output:
1 2 3 4 5 testing 7 8 9 10

Quick Sort code:
[Python]
Import random
 
Def qsort2 (array ):
If len (array) <= 1: return array www.2cto.com
Else: return qsort2 ([I for I in array [1:] if I <array [0]) + [array [0] + qsort2 ([I for I in array [1:] if I> = array [0])
 
Def qsort (array, left, right ):
If left> = right: pass
Else:
Print array, left, right
Low = left + 1
High = right
Index = left
While low <= high:
While low <= high and array [low] <array [index]:
Low + = 1
While low <= high and array [high]> = array [index]:
High-= 1
If low Array [low], array [high] = array [high], array [low]
If high> index:
Array [index], array [high] = array [high], array [index]
Print array, high
Print
Qsort (array, left, high-1)
Qsort (array, high + 1, right)
 
X = [random. randint (0,100) for I in range (10)]
Print x
Qsort (x, 0, 9)
Print x


Author: USTBHacker

Related Article

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.