Chris Barker writes:
On Mon, Mar 21, 2016 at 1:01 AM, Stephen J. Turnbull <stephen@xemacs.org> wrote:
AFAICS the OP's idea has a trivial and efficient expansion:
I'll take your word for it that this is efficient, and it is trivial in amount of code to write, but it is not the least bit trivial to read or write.
By "efficient" I mean only that the loop is unchanged. Bonus is that only one assignment and one test are needed outside of the loop. The only reason I could think of at the time that it might not be trivial to read is that a reader is unfamiliar with the "sentinel = object()" idiom. Otherwise, "for" and "if" are the most basic of Python syntax, so I felt safe in using that word. Writing is another matter, but that's covered under the "sometimes ya gotta be Dutch" clause. :-)
Howver, the motivating example was "the difference between *nothing**as error* and *nothing** as really empty*, GUI/Web interfaces display an explicit notice in case of empty lists to signify the correct execution of a process/action/search or the other case."
Sure -- but this seem to be mixing validation with processing code -- you really want to validate your inputs first.
If it's input, yes, but in my experience this would mostly be dealing with internal state such as a database. Then EAFP applies. For example, in paging, an empty page is a natural signal for end of content.
AND: this would mostly be containers,
"Mostly", maybe, but that's not to say that iterators are an unimportant case. And if your application involves a mix of containers and iterators, you may still prefer to use the same idioms for both cases.
All that being said:
how about "elempty"?, to go with elif?
-1 Not to my taste, to say the least.