2
我正在尋找檢索給定的關鍵是一個列表中的值。如何檢索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
。
我只是想知道我錯了,我用盡了一切:(
感謝您的時間
OMG,非常感謝你! :D我會盡快接受。 –
使用prn的另一個參數:'{「:a 0」「:b 1」}'是一個有效的哈希映射,但println使它看起來像完全不同(但也是有效的)。這不僅僅是一個理論上的問題,至少在我的代碼中,包含空格的字符串在哈希映射中非常有規律地出現。 – noisesmith