RRankTrell
Workflows

Coding workflows · Average ranks for ties

03
Built around your work

A concrete starting point

Assign one-based average ranks to at most 1000 finite numeric values while preserving their input positions. Check ties, negative values and empty input, rejecting Boolean values and non-finite floats before sorting.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

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

Average ranks for ties

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

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗