Like a list comprehension but with several lines

Hello Gus!

I was pondering a similar problem when I posted this suggestion. Based on this answer, your contrived loop can be rewritten in list comprehension syntax as follows:

out = [rand(s)[1]
       for i in 10:2:30
       for t = Ref(randperm(i))
       for s = Ref(maximum(t))]

Whether you prefer this, the for loop or the map syntax is a matter of taste.

HTH.

1 Like