It is not clear why you don't need to clip the end off of given_colors in the extend_max case--I think you do, but I haven't looked closely.
Instead of making a new variable, given_colors, and then chopping off one or both ends, you could generate slice indices:
```python
i0, i1 = 0, None
```
Then inside the "extended" block:
```python
if extend_min:
    i0 = 1
if extend_max:
    i1 = -1
```
Then in ListedColormap, use ```self.colors[i0:i1]```