Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/01bf679e59850bb7b3e639...



It 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)
   ])


Fantastic


cool!

  >>> l = ['a','b']
  >>> l[False]
  'a'
  >>> l[True]
  'b'
  >>> d = {0: 'a', 1: 'b'}
  >>> d[False]
  'a'
   >>> d[True]
  'b'
  >>> # TIL!


Where? I don't see anything in that code relying on that unless I'm Sunday blind.


`results[predicate(item)]` here they get the first and the second elements of a tuple. Essentially it’s `results[False]` and `results[True]`


Oh, that's obvious now. Must be that Sunday night blindness.


Results has 2 elements indexed by 0 and 1 (it’s a tuple not a dict)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: