Search code examples
stringdictionaryclojure

how to retrieve a key in a map whose value contains a particular substring in clojure?


i need to retrieve the key whose value contains a string "TRY"

:CAB "NAB/TRY/FIGHT.jar"

so in this case the output should be :CAB .

I am new to Clojure, I tried a few things like .contains etc but I could not form the exact function for the above problem.its easier in few other languages like python but I don't know how to do it in Clojure.

Is there a way to retrieve the name of the key ?


Solution

  • for can also filter with :when. E.g.

    (for [[k v] {:FOO "TRY" :BAR "BAZ"} 
          :when (.contains v "TRY")] 
            k)