def chrtonam(c):
    """Find unique elements in an iterable and in what order they appear.

Return a 3-tuple (uniqelements, eltoindex, map):
uniqelements -- elements in order of first appearance
eltoindex -- map from elements to their indices in uniqelements;
    equivalent to dict((el, i) for (i, el) in uniqelements)
map -- indices of uniqelements in the order in which they appeared,
    such that c[i] = uniqelements[map[i]]

"""
    d = {}
    nam = []
    for tile in c:
        d.setdefault(tile, len(d))
        nam.append(d[tile])
    chrdata = [None] * len(d)
    for (tile, tn) in d.items():
        chrdata[tn] = tile
    return chrdata, d, nam