RRankTrell
AI coding workspace

Average ranks for ties

RankTrell is a Windows AI coding client for examining ranking logic in source context. Open the project folder, compare the model’s proposed tie handling with your contract and review the resulting changes before applying them.

● ● ●RankTrell●
A concrete starting point · Average ranks for ties ×
from math import isfinite

def average_ranks(values):
    if type(values) not in (list, tuple) or len(values) > 1000:
        raise ValueError("values.container")
    values = tuple(values)
    if len(values) > 1000 or any(
        type(v) not in (int, float) or
        (type(v) is float and not isfinite(v)) for v in values
    ):
        raise ValueError("values.invalid")
    order = sorted(range(len(values)), key=values.__getitem__)
    result = [0.0] * len(values)
    first = 0
    while first < len(order):
        end = first + 1
        while end < len(order) and values[order[end]] == values[order[first]]:
            end += 1
        rank = (first + 1 + end) / 2
        for i in order[first:end]:
            result[i] = rank
        first = end
    return result
✳Assign one-based average ranks to at most 1000 finite numeric values while preserving their input positions.
✓ ChangesReview before applying ↗
Illustrative workspace
  1. Review before applying

    Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

  2. Connection

    Base URL, credentials and a reachable server.

  3. Project

    Check ties, negative values and empty input, rejecting Boolean values and non-finite floats before sorting.

Workflows

Average ranks for ties

Workflows ↗
A concrete starting point
from math import isfinite

def average_ranks(values):
    if type(values) not in (list, tuple) or len(values) > 1000:
        raise ValueError("values.container")
    values = tuple(values)
    if len(values) > 1000 or any(
        type(v) not in (int, float) or
        (type(v) is float and not isfinite(v)) for v in values
    ):
        raise ValueError("values.invalid")
    order = sorted(range(len(values)), key=values.__getitem__)
    result = [0.0] * len(values)
    first = 0
    while first < len(order):
        end = first + 1
        while end < len(order) and values[order[end]] == values[order[first]]:
            end += 1
        rank = (first + 1 + end) / 2
        for i in order[first:end]:
            result[i] = rank
        first = end
    return result
AI coding workspace

Give equal values an explicit place in the result

RankTrell is a Windows AI coding workspace for developers translating data rules into implementation changes. Open your project and describe how the application should treat equal values, missing results and the relationship between input and output order. Ask the connected model to inspect the calculation and its consumers, so the proposal answers the business rule rather than merely producing a sorted list.

The ranks.py context suggests a task around average ranks for tied values. You could ask for an explanation of how results map back to their original positions, then request a focused edit if your project behaves differently. Use small examples with known answers to keep that discussion concrete. Review both the tie policy and the representation returned to the rest of the application.

Once the implementation is ready to inspect, run your project checks on equal values, negative values and inputs the function should reject. Compare actual results with the examples agreed before editing. RankTrell supports OpenAI-compatible or Anthropic model endpoints, using credentials when required. You may choose an unrestricted AI model offered through that connection, subject to its provider conditions; tools and context limits depend on the model and server. A clear expected result remains more useful than confidence in a generated explanation.

Ranking rules to settle before accepting code

Should tied values receive different positions?

That depends on the ranking rule your application needs. State whether ties share an average rank, share another rank or use a secondary key. Ask for examples before implementation so the chosen policy is visible and testable.

Why preserve the relationship to original input order?

A consumer may need to attach each rank to the record that supplied the value. Check that mapping explicitly; a correctly sorted sequence can still assign results to the wrong records if positions are not restored.

Can invalid numbers simply sort to the end?

Only if that is your specified policy and consumers understand it. Otherwise require rejection or another explicit representation. Inspect numeric validation with the ranking code rather than allowing runtime comparison behavior to define the application rule.

How do I review a ranking refactor without a large dataset?

Begin with a few hand-checkable cases containing ties, distinct values and an empty input. Then run representative project data as needed. Small cases make policy differences easier to identify before broader validation adds volume.

Get the Windows app ↗

RankTrell · Updated 2026-10-25