def maxjoin(parts, char, length):
    """Join a number of parts such that the result is shorter than length."""
    joined = ""
    for part in parts:
        if len(joined) + len(part) < length:
            joined += "%s%s" % (part, char)
        else:
            return joined.rstrip(char)
    return joined