gpt4 book ai didi

将单字符串向量映射到 PersistentMap

转载 作者:行者123 更新时间:2023-12-01 12:45:30 26 4
gpt4 key购买 nike

我正在尝试通过 HashMap 音译列表,如下所示:

(map {"a" 0 "b" 1 "c" 2} ["a","c","b","a"])

我想吐槽一下:

[0,2,1,0]

我该怎么做?

更正:上面的方法有效,但这不行:

  (map {"a" 0 "b" 1 "c" 2} (vec "acba"))

这里有什么不同?

最佳答案

改用mapv

user=> (map {"a" 0 "b" 1 "c" 2} ["a" "c" "b" "a"])
(0 2 1 0)
user=> (mapv {"a" 0 "b" 1 "c" 2} ["a" "c" "b" "a"])
[0 2 1 0]

还有:

user=> (map {"a" 0 "b" 1 "c" 2} (vec "acba"))
(nil nil nil nil)
user=> (vec "acba")
[\a \c \b \a]
user=> (= \a "a")
false

这行得通(但是是迂回的):

user=> (mapv {"a" 0 "b" 1 "c" 2} (map str (vec "acba")))
(0 2 1 0)

关于将单字符串向量映射到 PersistentMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16405784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com