Question: PYTHON ONLY Write a program inverse_pernutation.py that accepts a permutation of the integers 0 through n - 1as n command-line arguments and writes its inverse.

PYTHON ONLY Write a program inverse_pernutation.py that accepts a permutation of thePYTHON ONLY

Write a program inverse_pernutation.py that accepts a permutation of the integers 0 through n - 1as n command-line arguments and writes its inverse. If the permutation is a list a. its inverse is the list b such that a[b[i]] = b[a[i]] = i. Be sure to check that the input is a valid permutation. If not, the program must exit with the message "Not a permutation" - you can do this by calling the function sys.exit(msg), where msg is the message you want to write. $ python inverse_permutation.py 12 3 4 5 Not a permutation. $ python inverse_permutation.py 5 3 4 0 12 3 4 5 1 2 0 $ python inverse_permutation.py 0 1 2 3 4 5 0 1 2 3 4 5 $ python inverse_permutation.py 5 4 3 2 10 5 4 3 2 1 0 import stdarray import studio import sys # Create a list perm consisting of the integers from the command line. perm = for V in # Define a variable n and set it to the number of elements in perm. n = # Hake sure perm represents a valid permutation. If not, exit the program # with the message "Not a permutation". Use a ID list exists of n booleans # for this purpose, exists = for i in if sys .exit() exists[] = # Invert the permutation into a list perm_inverted. perm_inverted = for i in perm_inverted[] = # Write the inverted permutation, separating each number by a space, and with # a newline at the end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!