Question about arguments passed to the filter function

Hi,

The code block below achieves its purpose but Julia provides a warning for how the argument is passed.


key1 = [ 1, 1, 2, 3, 3, 4]; key2 = [ 2, 3, 4, 4, 5, 5]
value = [0.3, 0.145, 0.032, 0.260, 0.320, 0.500]
Data = Dict{Tuple{Int64, Int64}, Float64}();
for i in 1:6
    Data[(key1[i],key2[i])] = value[i]    
end
filter(((k1,k2),v) -> k1 == 1, Data)

Is there a correct way to rewrite this so that the warning is not triggered?

Any help would be much appreciated.
Also, apologies if my question is posted in the wrong section of the forum (or not following the guidelines).
I am new to this…

Problem is that Dict iterator returns Pair not tuple of key-value. So, filter function is trying to destructure the Pair and gives you warning about it. Correct way (you may consider this example from the documentation) is to take whole pair as a single argument and destructure it inside the function

filter(p -> p.first[1] == 1, Data)
1 Like

Thank you for your help!

1 Like