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