Skip to content

idx [terminology]

Terminology

Usage

  • Use for a scalar index when naming the fact that it is an index matters.
  • Prefer idx over i when the variable persists beyond a small loop or appears in a compound name.
seen = {}
while rem:
    # If this remainder was seen before, digits from that point repeat.
    if rem in seen:
        repeat_idx = seen[rem]
        parts.insert(repeat_idx, "(")
        parts.append(")")
        break

    seen[rem] = len(parts)
    # ...

See 166. Fraction to Recurring Decimal.