Allowing missing item or attributes in operator's itemgetter and attrgetter

It would partially cover Indexable get method. [1,2,3].get(4) # None.

At least for cases where pre-building getter is sensible.

E.g. it would be a good option to get parameters from sequence:

get_params = itemgetter(*range(5), default=EMPTY)

assert len(sys.argv) <= 5
_, a, b, c, d = get_params(sys.argv)

Apart from that, I use itemgetter and attrgetter extensively and making these more functional would certainly be beneficial.

1 Like