Hacker News new | ask | show | jobs
by thomasahle 3742 days ago
It also helps on how ifs should be inserted, for example:

  ys = []
  for x in xs:
    if P(x):
      for y in Y(x):
        if Q(x,y):
          ys.append(y)
Becomes

  [y
     for x in xs
     if P(x)
     for y in Y(x)
     if Q(x,y)
  ]
Surely combining this many for/if's may often be the wrong idea. Just like making a depth 4 iterative loop isn't always ideal. It does make the order easier to remember though :)