How to filter out Dict based on the value of subdict

I have a Dict:

  UNITS = Dict([
    "BUHLER2" => Dict(["cap" => 2000, "mincap" => 60, "dcap" => 49660, "util_cost1" => 2, "maxprodr" => 49660]), 
    "BUHLER1" => Dict(["cap" => 1500, "mincap" => 60, "dcap" => 37245, "util_cost1" => 1.8, "maxprodr" => 37245]), 
    "CINTAS" => Dict(["cap" => 1000, "mincap" => 50, "dcap" => 24830, "util_cost1" => 1.4, "maxprodr" => 24830]), 
    "V500" => Dict(["cap" => 500, "mincap" => 45, "dcap" => 12415, "util_cost1" => 1.2, "maxprodr" => 12415]), 
    "V150" => Dict(["cap" => 160, "mincap" => 45, "dcap" => 3973, "util_cost1" => 1, "maxprodr" => 3973])
    ])  

Now I am trying to filter-out some entries based on the “cap” value, I’ve tried this way:

filter((k, v) -> v["cap"] != 160.0, UNITS)

But I am having an error:

ERROR: MethodError: no method matching (::var"#17#18")(::Pair{String,Dict{String,V} where V})
Closest candidates are:
  #17(::Any, ::Any) at REPL[17]:1
Stacktrace:
 [1] filter(::var"#17#18", ::Dict{String,Dict{String,V} where V}) at .\abstractdict.jl:428
 [2] top-level scope at REPL[17]:1

I guess the problem is in (k, v), but I am clueless what to change there to enable it working.

Can anyone assist, please?

Replace (k, v) by kv as function argument and then obtain the value via kv[2].

2 Likes