Indexable get method. [1,2,3].get(4) # None

These are not equivalent because this version silently accepts more than 3 items (or it would if the index was corrected).

Also I don’t consider that to be more readable. This is what I meant when I said:

Many of the examples are expressing some nontrivial conditionality that I would want to show more explicitly in an if/else statement

The complexity of most code comes from conditionality. I always want to separate that conditionality from everything else so that it is clearly seen and handled in one place.

It’s not about being concerned about efficiency: this seems like the sort of thing that just should not happen in a hot loop. If you want to optimise a hot loop then you decide ahead of time where something is going to be a 2-tuple or a 3-tuple rather than writing a function that doesn’t know what it is going to get.

1 Like