Chris Angelico writes:
## New "unless" construct for list displays and argument lists ##
Inside a list/dict/set/tuple display, or inside an argument list, elements can be conditionally omitted by providing a predicate.
lst = [f1(), f3() unless f2(), f4()]
Not a fan of this in displays, YMMV. IME the cases where I could use this are generally well-served by comprehensions with if clauses. (I'm speaking for myself only, I have no idea if others have "more than once in a blue moon" use cases.) OTOH foo(f1(), f3() unless f2(), f4()) looks horrible to me, a definite -1. Yes, I know about varargs functions, but "positional" means positional to me. Surely this would almost always be a runtime error in format() if not f2(), for example. It would have to be used quite frequently for me to get over the awkwardness, I think. Granted, foo(*[f1(), f3() unless f2(), f4()]) is horrid, too (and if you wanted to use a tuple for efficiency it would be unreadable). But how often would you want to call varargs with arguments that might not even be there? Would args = (f1(), f3() unless f2(), f4()) foo(*args) be so bad for the rare occasion? (Maybe it's not so rare for others, but I can't recall ever wanting this, while list displays with variable desired length do come up.) Steve