4 ms·
It's funny the author throws a dig at Python for its syntax that actively discourages this kind of code. Like… my guy you're not taking the hint. Python makes t
by Spivak 2y ago
It's funny the author throws a dig at Python for its syntax that actively discourages this kind of code. Like… my guy you're not taking the hint. Python makes things it doesn't want you to do ugly as sin. It's why lambda is so awkward and clunky.
- deleted 2y ago[deleted]
- rolux 2y agoYes. The following is a lot more concise: a = [1, 2, 3, 4] print([v*v for v in reversed(a) if v*v % 2 == 0])
- libria 2y agoI think the above is a good idea of what's wrong with python (and Go), because in your example the list comp is evaluated in what seems to be this order: FOURTH-> print([THIRD-> v*v for v in FIRST-> reversed(a) if SECOND-> v*v % 2 == 0]) Which is all over the place. I'd rather see: a = [1, 2, 3, 4] a = reversed(a) a = [v*v for v in a] a = [w for w in a if a % 2 == 0] print(a)
- alfons_foobar 2y agoThis. I often use generator expressions for the intermediate values (so I don't allocate a new list for each step), but I find this to be much more readable.
- xnacly 2y agoI get that, i still dont like to write f5(f4(f3(f2(f1())))) instead of writing f1().f2().f3().f4().f5()