def _categories_level(keys):
    res = []
    for i in zip(*(keys)):
        tuplefied = _tuplify(i)
        res.append(list(OrderedDict([(j, None) for j in tuplefied])))
    return res
use the Ordered dict to implement a simple ordered set
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/graphics/mosaicplot.py/_categories_level