def recycle_palette(palette, size):
    """Cycle through a palette (list) until it reaches desired length (int)."""
    length = len(palette)
    nrepeat = (size // length) + 1
    out = palette * nrepeat
    return out[0:size]