Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Ask HN: Good Python codebases to read?. Parent comment
For instance, I find this unnecessarily difficult to read.
>>> 0 if True else 1 if True else 2
0
But breaking it up like this keeps it reasonably concise, while retaining readability.
if True: a = 0 if True else 1 else: a = 2 print(a)
>>> import random
>>> ['a' if random.choice((True, False)) else 'b' for _ in range(6)]
['a', 'a', 'a', 'a', 'a', 'b']
There are no comments on this comment yet.
For instance, I find this unnecessarily difficult to read.
>>> 0 if True else 1 if True else 2
0
But breaking it up like this keeps it reasonably concise, while retaining readability.
They can also be combined with comprehensions, which can be useful.>>> import random
>>> ['a' if random.choice((True, False)) else 'b' for _ in range(6)]
['a', 'a', 'a', 'a', 'a', 'b']