`dict`s have a convenient version of the `get`:

> 
> `get(key[, default])`
> 
> 
> Return the value for key if key is in the dictionary, else default. **If
>  default is not given, it defaults to None, so that this method never
>  raises a `KeyError`.**
> 
> 
> 

Bold emphasis mine, because I looked and could not find an equivalent version for lists. So I implemented my own:

```
In [148]: class myList(list):
     ...:     def pop(self, idx=-1, default=None):
     ...:         try:
     ...:             return super().pop(idx)
     ...:         except IndexError:
     ...:             return default

```

This works as expected:

```
In [149]: l = myList([1, 2, 3, 4, 5])

In [150]: l.pop()
Out[150]: 5

In [151]: l.pop(12345, 'default')
Out[151]: 'default'

```

Since this works, this can also be extended to sets. Anyway, I've got a couple of questions:

1. Is there an easier/inbuilt/3rd party equivalent to what I've done that doesn't require me to extend the `list` class?
2. If there isn't, is there any particular reason why? I believe this would be a useful behaviour to have.

Some particular use cases I can think of would be calling `pop` on a list whose size you don't know, in a place you don't want to, or can't catch errors, such as a list comp.

---

[This question](https://stackoverflow.com/questions/2574636) explores the same topic but the answers do not suit my requirement, as I have explained above.