This works for Julia 0.3.5:

julia> ll = Vector{Int}[[1,2],[1,2,3],[7]]
3-element Array{Array{Int64,1},1}:
 [1,2]  
 [1,2,3]
 [7] 

sort(ll, by=length)
3-element Array{Array{Int64,1},1}:
 [7]    
 [1,2]  
 [1,2,3]



On Tuesday, January 27, 2015 at 2:02:10 AM UTC+9, Wai Yip Tung wrote:
>
> I'm trying to construct a list of list and do some operation on it. In 
> Python I would do
>
> In [7]: ll = [[1,2],[1,2,3],[7]]
>
> Say I want to sort them by the length of the list, many function accepts a 
> `key` parameter. In this case I want the `key` to be `len`.
>
> In [8]: max(ll, key=len)
> Out[8]: [1, 2, 3]
>
> In [9]: sorted(ll, key=len)
> Out[9]: [[7], [1, 2], [1, 2, 3]]
>
> In Julia, if I enter the literal  [[1,2],[1,2,3],[7]], then are join to 
> together into a long list. Through many trial and error I found a way by
>
> ll = (Array)[[1,2],[1,2,3],[7]]
>
> What is the proper way to construct a list of list?
>
> Secondly, Julia's sort support a `by` parameter that does what `key` do in 
> Python. But there is no equivalent in `maximum`. What is the recommended 
> way to find the longest list in the data structure?
>
> Wai Yip
>

Reply via email to