如何检索HloMap中的键值,该值是Clojure中的列表?

时间:2016-05-01 01:25:28

标签: string clojure hashmap

我正在寻找一个给定密钥的值,这是一个列表。

    (defn string-tuple [my-string]
      (partition 2 1 my-string))

    (defn split-and-frequent-tuple [lines]
      (frequencies (string-tuple lines)))

    (defn split-and-frequent [lines]
      (frequencies lines))

(defn string-split [my-string]
  (str/split my-string #" "))


    (def string-pairs (split-and-frequent-tuple (string-split "<s> I am Sam </s> <s> Sam I am </s> <s> I do not like green eggs and ham </s>")))

    ;; Calculate that bigram probability
    (println string-pairs)
    (println (string-pairs '(green eggs)))

基本上,字符串对计算文本中出现类似(绿色蛋)的项目数量的频率。但是,当我尝试使用类似(string-pairs '(green eggs))之类的内容检索密钥时,即使地图显示该密钥的值为1,我也总是返回nil

我只是想知道我哪里出错了,我已经尝试了所有事情:(

感谢您的时间

1 个答案:

答案 0 :(得分:2)

使用println显示值时,字符串和符号看起来相同,即使它们不相等。

进行调试时,请使用明确显示值的prn,或使用pr-str生成prprn将使用的字符串println打电话。

这应该给你正确的结果(如果Clojure的内容相等,则向量和列表在Clojure中是相同的。)

(string-pairs ["green" "eggs"])