A Python script that reads an array of integers from standard input and prints them in reverse order.
https://github.com/davidbmar/pythonArrays2 · public · shipped
A simple command-line utility designed for educational purposes to demonstrate basic array manipulation and standard I/O handling in Python. It solves the specific algorithmic task of reversing an integer array provided via stdin.
echo '4\n1 4 3 2' | python pythonArrays.py
flowchart TD
A[User Input] -->|stdin| B(pythonArrays.py)
B --> C{Parse Input}
C -->|Split & Map| D[Integer Array]
D --> E[Reverse Iteration Loop]
E -->|sys.stdout.write| F[Console Output]
The project consists of a single Python script (`pythonArrays.py`) that utilizes `sys` for output control and built-in functions for input parsing. It manually iterates through the array indices in reverse order to construct the output string.
sequenceDiagram
participant User
participant Script as pythonArrays.py
participant Sys as sys module
User->>Script: Provide n (size) and array elements
Script->>Script: Parse n via raw_input()
Script->>Script: Parse array via map(int, split())
loop For i in range(n)
Script->>Script: Calculate reverse index x = n - i - 1
Script->>Sys: Write str(arr[x]) + " "
end
Sys-->>User: Display reversed array
Use this script as a reference for basic Python input/output operations, specifically handling space-separated integer inputs and controlling output formatting without trailing newlines using `sys.stdout.write`. It serves as a baseline solution for HackerRank-style array reversal challenges.
✓ all on main — nothing unmerged.