What would be an equivalent julia code

It works though; Make sure lst is a Vector (List) of dictionaries, and not a dictionary itself (Same as the Python code):

julia> lst = [Dict("n" => 4), Dict("n" => 2), Dict("n" => 8), Dict("n" => 6)]
4-element Vector{Dict{String, Int64}}:
 Dict("n" => 4)
 Dict("n" => 2)
 Dict("n" => 8)
 Dict("n" => 6)

julia> function average_by(lst; fn = x -> x)
         return sum(map(fn, lst)) / length(lst)
       end
average_by (generic function with 1 method)

julia> average_by(lst; fn = x -> x["n"])
5.0

2 Likes