def tuplize(dlist, d, name):
    """
    Convert a list into a list of tuples.
    """
    if len(dlist) % d != 0:
        raise ValueError('Cannot tuplize data for set ' + str(name) +
            ' because its length ' + str(len(dlist)) +
            ' is not a multiple of dimen ' + str(d))
    j = 0
    t = []
    rv = []
    for i in dlist:
        t.append(i)
        j += 1
        if j == d:
            rv.append(tuple(t))
            t = []
            j = 0
    return rv
