Haskey function in Julia

I am a bit confused by a small point of the following piece of code.

function filter_walkways(ways::Vector{OpenStreetMapX.Way}, classes::Dict{String, Int}=OpenStreetMapX.PEC_CLASSES; levels::Set{Int} = Set(1:length(OpenStreetMapX.PED_CLASSES)))
      walkways = OpenStreetMapX.Way[]
      for way in walkways
           sidewalk = get(way.tags, "sidewalk", "")
           if sidewalk != "no"
               if haskey(classes, "sidewalk:$(sidewalk)") && classes["sidewalk:$(sidewalk)"] in levels
                    push!(walkways, way)
               elseif haskey(classes, way.tags["highways"]) && classes[way.tags["highway"]] in levels
                     push!(walkways, way)
      return walkways

I was mainly confused about the haskey(classes, "sidewalk:$(sidewalk)"). I thought I can simply use haskey(classes, sidewalk) instead. Could anyone kindly let me know the reason?

Presumably the keys in the classes Dict have an additional "sidewalk:" prepended compared to the tags coming out of the way object?

Assume e.g. that sidewalk = "narrow", then doing haskey(classes, sidewalk) checks for the key "narrow" in the Dict, while haskey(classes, "sidewalk:$(sidewalk)") would check for the key "sidewalk:narrow"


Thank you for your quick reply. I figured it out with the same as what you said, after trying some examples. :wink:

1 Like