Get Mystery Box with random crypto!

Daily Productive Sharing 534 - Do Stupid Things Thorsten Ball | DPS Main

Daily Productive Sharing 534 - Do Stupid Things

Thorsten Ball 建议我们多写笨代码 -- 那些能解决问题,不花里胡哨的代码,正如奥卡姆剃刀原理所言。
举个例子,Python 里的 list comprehension 是 for loop 的一种写法,在不少情况下两者可以互换,甚至两层嵌套的 for 循环或者有条件判断的 for 循环也可以改写成 list comprehension 。但后面这两种情况的 list comprehension 并不是很容易懂,也容易写错。如果不熟悉的话,不如还是按照“笨办法”写成 for loop。
k = [[1, 3], [4, 5]]
r = [i * 6 for j in k for
i in j if i > 2]

r = []
for j in k:
for i in j:
if i > 2:
r.append(i * 6)

https://letters.acacess.com/daily-productive-sharing-534/

更多精彩内容都在生产力日报 https://letters.acacess.com/#/portal/signup/yearly