2

编辑:

我的问题是如何过滤掉 zipmap 中似乎是空白键的内容?

尽管我有解决问题的方法,但知道如何过滤密钥会很有帮助。

结束编辑:

这个输出

:   [: [ ]]   ([ ])   3   ,,

(println first-ent, " ", map-ent, " ", val-ent, " ", (count out-csv), " ", out-csv)

在这个函数中

(defn missing-accts 
    "Prints accounts found in one report but not the other."

    [report-header mapped-data out-file]
    (spit out-file (str "\n\n" report-header "\n\n") :append true)

    (doseq [map-ent mapped-data]
            (let [first-ent (first map-ent)
                  val-ent   (rest  map-ent)
                  out-csv   (if first-ent
                                (str (name (key map-ent)) "," (first (val map-ent)) "," (last (val map-ent)) "\n")
                                nil)]

                (println first-ent, " ", map-ent, " ", val-ent, " ", (count out-csv), " ", out-csv)
                (if (> (count out-csv) 3)                    
                    (spit out-file out-csv :append true)
                    (println "Skipping: ", out-csv)))))

带有空白键的输出的计数为 3 的事实使我可以进行过滤,这一事实似乎不像能够检测到空白键那样干净。找到并过滤掉一个空白键是让我难过的地方。

谢谢你。

4

1 回答 1

5

您可以使用以下方法创建空白关键字:

(keyword "")

您可以使用它来过滤您的列表并删除所有空白关键字:

(filter (fn [[key _]] (not= (keyword "") key)) map-ent)
于 2012-04-19T10:19:53.953 回答