A Python script that separates even and odd indexed characters from input strings.
https://github.com/davidbmar/stringsAndLoops · public · shipped
A command-line utility designed for coding challenges that processes a series of strings, splitting each into two parts: characters at even indices and characters at odd indices, then prints them space-separated.
python stringsAndLoops.py
flowchart TD
A[Start] --> B[Read Test Case Count]
B --> C{More Cases?}
C -->|Yes| D[Read Input String]
D --> E[Initialize Even/Odd Lists]
E --> F[Iterate Characters]
F --> G{Index Even?}
G -->|Yes| H[Append to Even List]
G -->|No| I[Append to Odd List]
H --> J{Next Char?}
I --> J
J -->|Yes| F
J -->|No| K[Join Even List]
K --> L[Join Odd List]
L --> M[Print Result]
M --> C
C -->|No| N[End]
Built with pure Python using standard I/O. It reads the number of test cases from stdin, iterates through each string, classifies characters by index parity into separate lists, and writes the concatenated results to stdout.
sequenceDiagram
participant User
participant Script
participant SysStdout
User->>Script: Provide Test Case Count (N)
loop For each test case
User->>Script: Provide Input String (S)
Script->>Script: Initialize evenString, oddString
loop For each char in S
Script->>Script: Check index parity
alt Even Index
Script->>Script: Append to evenString
else Odd Index
Script->>Script: Append to oddString
end
end
Script->>SysStdout: Write evenString chars
Script->>SysStdout: Write space
Script->>SysStdout: Write oddString chars
Script->>SysStdout: Write newline
end
Use this as a reference for basic string manipulation, list accumulation patterns, and handling standard input/output in Python 2 environments. It demonstrates O(N) character processing per string.
✓ all on main — nothing unmerged.