-6ren">
gpt4 book ai didi

dictionary - 有没有一种优雅的方法来改变clojure映射的键?

转载 作者:行者123 更新时间:2023-12-04 21:56:09 24 4
gpt4 key购买 nike

我想更改 map :

{"a" 1 "b" 2}

{:a 1 :b 2} 

如何在 Clojure 中做到这一点?

最佳答案

您可以使用keywordize-keys函数来做到这一点。

user=> (clojure.walk/keywordize-keys {"a" 1 "b" 2})
;=> {:a 1 :b 2}

user=> (require '[clojure.walk :refer [keywordize-keys]])
;=> nil
user=> (keywordize-keys {"a" 1 "b" 2})
;=> {:a 1, :b 2}

关于dictionary - 有没有一种优雅的方法来改变clojure映射的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26331835/

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