3 ms·
For-else could be useful, but I don't think Python's semantics would actually help here? Python's for-else runs when the for loop did not break (even if nonempt
by deredede 4y ago
For-else could be useful, but I don't think Python's semantics would actually help here? Python's for-else runs when the for loop did not break (even if nonempty), but what would be needed here would be to run when the for loop was empty, which is a different condition.
cpp2 is both interesting and ambitious, I really hope it gets somewhere.
- gpderetta 4y agoIndeed, I misremembered the semantics of for-else! I don't think I have actually used it in python :)
- deredede 4y agoYeah for-else as implemented in Python is... not actually that useful. It's the right tool to inline std::find_if and that's basically it. I think the behavior you had in mind would actually be more intuitive and more useful. OTOH, try...else I find myself missing at times.