rcslice - 1-Indexed List Slicing

1.1.0 · active · verified Thu Apr 16

rcslice is a Python library (version 1.1.0) designed to slice lists of 'sliceables' using a 1-indexed system where both start and end indices are inclusive. This utility helps in specific use cases, such as slicing file content line by line or column by column, offering an alternative to Python's native 0-indexed, end-exclusive slicing. It appears to be a stable, focused utility with infrequent releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate `RowSlice` and perform basic row and column slicing. It also illustrates how to use a custom separator when combining multiple slice operations, which is crucial for controlling output formatting.

from rcslice import RowSlice

# Create a list of sliceable items
data = [
    "Header 1,Header 2,Header 3",
    "Row 1 Col 1,Row 1 Col 2,Row 1 Col 3",
    "Row 2 Col 1,Row 2 Col 2,Row 2 Col 3",
    "Row 3 Col 1,Row 3 Col 2,Row 3 Col 3",
    "Row 4 Col 1,Row 4 Col 2,Row 4 Col 3"
]

# Initialize RowSlice (no separator for single slice operations)
rs = RowSlice()

# Example 1: Slice rows 1 to 3 (inclusive)
# Input '1-3' means first element to third element
print("\n--- Slicing rows 1-3 ---")
sliced_rows = rs.slice(data, '1-3')
for item in sliced_rows:
    print(item)

# Example 2: Slice row 2, column 2 (1-indexed)
print("\n--- Slicing Row 2, Column 2 ---")
sliced_single_cell = rs.slice(data, '2.2')
for item in sliced_single_cell:
    print(item)

# Example 3: Multiple slices with a custom separator
# Slices: row 1-2, then row 4
# The separator ['---'] means a single '---' line will be inserted between the slices.
rs_with_separator = RowSlice(['---'])
print("\n--- Multiple Slices with Separator (rows 1-2, then row 4) ---")
multi_sliced_data = rs_with_separator.slice(data, '1-2,4')
for item in multi_sliced_data:
    print(item)

view raw JSON →