Nested list comprehensions in Julia

前端 未结 5 1025
无人共我
无人共我 2021-02-13 16:14

In python I can do nested list comprehensions, for instance I can flatten the following array thus:

a = [[1,2,3],[4,5,6]]
[i for arr in a for i in arr]
         


        
5条回答
  •  忘了有多久
    2021-02-13 16:25

    This feature has been added in julia v0.5:

    julia> a = ([1,2,3],[4,5,6],[7,8,9])
    ([1,2,3],[4,5,6],[7,8,9])
    
    julia> [i for arr in a for i in arr]
    9-element Array{Int64,1}:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    

提交回复
热议问题