← Back to context

Comment by lgas

12 hours ago

Always returning the empty list meets your spec.

Good point. I suppose we should add "number of input elements equals number of output elements" and "every input element is present in the output". Translated in a straightforward test that still allows my_sort([1,1,2]) to return [1,2,2], but we have to draw the line somewhere

  • Just use Counter and if the objects aren’t hashable, use the count of IDs. Grab this before calling the function, in case the function is destructive. Check it against the output.

    Add in checking each item is less than or equal to its successor and you have the fundamental sort properties. You might have more, like stability.

  • > we have to draw the line somewhere

    Do we? You can pop-count the two lists and checks that those are equal.