Hacker News new | ask | show | jobs
by HCIdivision17 3262 days ago
I thought, "gosh, that seems at least marginally useless; why wouldn't that short circuit?" and then just tried it. I tried a few variations, and about the only use I can think of is to signal as a side effect for when the dict is made.

Fun trick to learn exists. Though I would really like to know what led up to it, since it seems ... unhelpful.

Edit: Looking at other comments, I did try popping off that entry in the dict, and no, it didn't have anything in it (it doesn't make the dict anything like defaultdict).

1 comments

As far as I know there is no native mechanism for short circuiting in Python. So anything that short-circuits should be considered a special case.
Binary operations will do it, like in `True or foo()`, but there's no real lazy evaluation machinery for parameters to a function. (Yet? I bet someone's working on it... at least I haven't tried any packages like lazypy for it.)