Skip to content

Instantly share code, notes, and snippets.

@jkk
Created November 4, 2010 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkk/662064 to your computer and use it in GitHub Desktop.
Save jkk/662064 to your computer and use it in GitHub Desktop.
(ns user
(:require [clojure.string :as str]
[clojure.java.io :as io]))
(def postcode-trie
(with-open [r (io/reader "/Users/tin/src/clj/playground/postcodes.txt")]
(reduce
(fn [trie line]
(let [[postcode region] (.split line ",")
postcode (str/replace postcode " " "")]
(assoc-in trie postcode region)))
{}
(line-seq r))))
(get-in postcode-trie "SW1A2")
;; => "20"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment