3 ms·
Very well written. Fun little tidbit, Django abuses the fact that bools are ints in it's partition util: https://github.com/django/django/blob/01bf679e59850bb7
by DangitBobby 5y ago
Very well written. Fun little tidbit, Django abuses the fact that bools are ints in it's partition util:
https://github.com/django/django/blob/01bf679e59850bb7b3e6395f1683bd1463ed9969/django/utils/functional.py#L414 https://github.com/django/django/blob/01bf679e59850bb7b3e639...
- hultner 5y agoWhere? I don't see anything in that code relying on that unless I'm Sunday blind.
- iezepov 5y ago`results[predicate(item)]` here they get the first and the second elements of a tuple. Essentially it’s `results[False]` and `results[True]`
- hultner 5y agoOh, that's obvious now. Must be that Sunday night blindness.
- NegativeLatency 5y agoResults has 2 elements indexed by 0 and 1 (it’s a tuple not a dict)
- int_19h 5y agoIt does make for some amusing code golf techniques, e.g.: print([ f"{(not x % 3) * 'Fizz'}{(not x % 5) * 'Buzz'}" or x for x in range(1, 20) ])
- DangitBobby 5y agoFantastic
- np_tedious 5y agocool! >>> l = ['a','b'] >>> l[False] 'a' >>> l[True] 'b' >>> d = {0: 'a', 1: 'b'} >>> d[False] 'a' >>> d[True] 'b' >>> # TIL!