# How to filter out Dict based on the value of subdict

**URL:** https://discourse.julialang.org/t/how-to-filter-out-dict-based-on-the-value-of-subdict/47914
**Category:** General Usage
**Created:** [October 7, 2020, 7:23am UTC](https://discourse.julialang.org/t/how-to-filter-out-dict-based-on-the-value-of-subdict/47914 "2020-10-07T07:23:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sogrbilja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sogrbilja/32/17521_2.png) [@sogrbilja](https://discourse.julialang.org/u/sogrbilja)
#### Post date: [October 7, 2020, 7:23am UTC](https://discourse.julialang.org/t/how-to-filter-out-dict-based-on-the-value-of-subdict/47914/1 "2020-10-07T07:23:19Z")

</div>

I have a Dict:

```julia
  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:

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

```

But I am having an error:

```julia
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?

---

<div class="post-metadata">

### Author: ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)
#### Post date: [October 7, 2020, 7:35am UTC](https://discourse.julialang.org/t/how-to-filter-out-dict-based-on-the-value-of-subdict/47914/2 "2020-10-07T07:35:16Z")

</div>

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