On 8/28/20 8:24 AM, David Mertz wrote: > > As a side note, I don't really get why everyone else thinks a > try/except is the most natural approach while a ternary seems more > obvious to me for this situation. But it kinda connects to me liking > list.get() better, I think... since "not enough items" doesn't seem as > *exceptional* to me as it apparently does to some others.
try/except is specifically looking for the error in question, index out of bounds. The ternary requires restating in other words the bounds limit. For instance, for a list of N items, the allowable subscripts are -N to N-1, and the sample ternary is only checking for the upper bound, not the lower, so fails an too small of an index (maybe you know you are only using positive indexes?) Missing this won't happen with try/except. -- Richard Damon _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XGEFOQIG7DHNXYV3R554TG2KJ6J6R7BM/ Code of Conduct: http://python.org/psf/codeofconduct/