gpt4 book ai didi

clojure - 如何在 map 内创建 map ?

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

我有一张包含电子邮件和密码的 map ,看起来像这样......

 {"email1" "password1","email2" "password2","email3" "password3"}

我需要在 map 中制作一张 map ,其中将包含电子邮件作为关键字(我想我解释得很好,我是 clojure 的新手)。

如何使用这些值创建 map ?
 {"email1" {"email1" "password1"},"email2" {"email2" "password2"},"email3" {"email3" "password3"}}

我试过 zipmap 但我得到的是矢量而不是 map ...
 {"email1" ["email1" "password1"],"email2" ["email2" "password2"],"email3" ["email3" "password3"]}

最佳答案

(def m {"email1" "password1","email2" "password2","email3" "password3"})

(into {} (map (fn [[k v]] [k {k v}]) m))
;= {"email2" {"email2" "password2"}, "email1" {"email1" "password1"}, "email3" {"email3" "password3"}}

关于clojure - 如何在 map 内创建 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23072521/

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