Yesterday, I posted this post about a method of sorting I'd been thinking about for a while. I also posted what I think is a solution in terms of an algorithm and a Python implementation.
Not having real data to play with, I thought I'd try some random tests.
So, here's the Python code below for getting random results and the output from running the random results generator a few times. In the output, I had results from the "b" list print out with an indentation to make it easier to see that while the results are intermixed, the original ordering per the "a" and "b" sets stays intact.
Yeah, I know nobody cares about any of this except me, but this blog is largely a self-reference library for myself.
from duck_sort import duck_sort import random ## auto-add tuple of data and random scores to list. def make_rand(array, array_name): limit = random.randrange(1,10) for i in range(1,limit): name = str(array_name) + str(i) md = (name, random.randint(0,100)) array.append(md) return array ## fill lists with random data, output results. def duck_test(): a =  b =  make_rand(a, "a") make_rand(b, "b") ## use duck_sort() on random data; print results. for result in duck_sort(a,b): tab = "" if result == "b": # for reading ease. tab = "\t" print tab + str(result)
>>> duck_test() ('a1', 52) ('a2', 60) ('a3', 95) >>> duck_test() ('b1', 37) ('a1', 14) >>> duck_test() ('a1', 45) ('b1', 36) ('b2', 39) ('b3', 14) ('b4', 65) ('b5', 48) ('b6', 33) ('a2', 11) ('a3', 51) ('a4', 30) ('a5', 31) ('a6', 57) >>> duck_test() ('a1', 90) ('b1', 85) ('b2', 34) ('b3', 39) ('a2', 21) ('a3', 92) ('a4', 18) ('b4', 2) ('b5', 76) ('b6', 57) ('b7', 11)--------------