I would like to pluck an item from a list and return a default if not found (instead of usual index exception). Very similar to get(key, default) on a dictionary. After perusing the docs, it feels like I still overlooked a trivial built-in python solution that provides this.
Here's the fastest I could come up with:
def pluck(list_items, index, default=None):
return dict(zip(range(len(list_items)), list_items)).get(index, default)
s = [1, 2,]
pluck(s, 3, None)
Thanks!