human
I wrote the below code

    if (ndupe_l is None):
        ndupe_l = ([1] * nlevels)
    assert (is_sequence(ndupe_l) and (len(ndupe_l) <= nlevels))
    assert ((names is None) or (names is False) or (names is True) or (len(names) is nlevels))
    assert ((idx_type is None) or ((idx_type in ('i', 'f', 's', 'u', 'dt', 'p', 'td')) and (nlevels == 1)))
    if (names is True):
        names = [(prefix + str(i)) for i in range(nlevels)]
    if (names is False):
        names = None
    if (isinstance(names, compat.string_types) and (nlevels == 1)):
        names = [names]
    idx_func = dict(i=makeIntIndex, f=makeFloatIndex, s=makeStringIndex, u=makeUnicodeIndex, dt=makeDateIndex, td=makeTimedeltaIndex, p=makePeriodIndex).get(idx_type)
    if idx_func:
        idx = idx_func(nentries)
        if names:
            idx.name = names[0]
        return idx
    elif (idx_type is not None):
        raise ValueError(('"%s"    is    not    a    legal    value    for    `idx_type`,    use        "i"/"f"/"s"/"u"/"dt/"p"/"td".' % idx_type))
    if (len(ndupe_l) < nlevels):
        ndupe_l.extend(([1] * (nlevels - len(ndupe_l))))
    assert (len(ndupe_l) == nlevels)
    assert all([(x > 0) for x in ndupe_l])
    tuples = []
    for i in range(nlevels):
        def keyfunc(x):
            import re
            numeric_tuple = re.sub('[^\\d_]_?', '', x).split('_')
            return lmap(int, numeric_tuple)
        div_factor = ((nentries // ndupe_l[i]) + 1)
        cnt = Counter()
        for j in range(div_factor):
            label = ((prefix + ('_l%d_g' % i)) + str(j))
            cnt[label] = ndupe_l[i]
        result = list(sorted(cnt.elements(), key=keyfunc))[:nentries]
        tuples.append(result)
    tuples = lzip(*tuples)
    if (nentries == 1):
        index = Index(tuples[0], name=names[0])
    else:
        index = MultiIndex.from_tuples(tuples, names=names)
    return index

What's a good function header?
assistant
#Here is Python code to fix + str(i)) for i in range(nlevels)]
.

def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None, idx_type=None):