an implementation of categorize code

An implementation of the categorize code.

Here is the python, presumably it is correct, I haven't tested it recently:
def metric_mbr(metric,x,thresh,data):
  for elt in data:
    if metric(x,elt) <= thresh: -- depending on if 0 or 1 means exact match, you may want to swap to: >= thresh 
      return True
  return False

def categorize_list(data,metric,thresh):
  out_list = []
  for x in data:
    n = 0
    del_list = []
    for i in range(len(out_list)):
      if metric_mbr(metric,x,thresh,out_list[i]):
        if n == 0:
          idx = i
          n = 1
          out_list[idx] += out_list[i]
    if n == 0:
      out_list = [x for index, x in enumerate(out_list) if index not in del_list]
  return out_list
And that's it. BTW, yeah O(n^3) I think!

previous: introducing bridging sets
next: a bko version of categorize

updated: 19/12/2016
by Garry Morrison
email: garry -at-