Python provides an example to flip an array.
This example describes how to use Python to flip an array. We will share this with you for your reference. The details are as follows:
Description
Given an integer array a with a length of n, the elements are not the same. to check whether such a segment exists in the array, you can only flip the segment to sort the entire array in ascending order. The array fragment [l, r] indicates the sequence a [l], a [l + 1], sequence..., and sequence a [r]. The original array is
A [1], a [2],..., a [L-2], L-1], a [l], a [l + 1],..., a [r-1], a [r], a [r + 1], a [r + 2],..., a [n-1], a [n],
The array after the reverse order of the [l, r] segment is
A [1], a [2],..., a [L-2], L-1], a [r], a [r-1],..., a [l + 1], a [l], a [r + 1], a [r + 2],..., a [n-1], a [n].
Input
The first row of data is an integer: n (1 ≤ n ≤ 105), indicating the length of the array.
The second row of data is n integers a [1], a [2],..., a [n] (1 ≤ a [I] ≤ 109 ).
Output
Output "yes". If yes; otherwise output "no", no quotation marks are required.
Sample output
Yes
Sample Input
4
2 1 3 4
Implementation Code:
While 1: n = int (raw_input () x = raw_input () breakx = [int (I) for I in x. split ()] y = [I for I in x] y. sort () partx = [x [I] for I in range (n) if x [I]! = Y [I] party = [y [I] for I in range (n) if x [I]! = Y [I] party. reverse () if partx = party: print "yes" else: print "no"