def pad(base, fill, count, right = False):
    """Pad base string with given fill until count, on either left or right."""

    while len(base) < count:
        if right:
            base += fill
        else:
            base = fill + base
    return base