One-line Tree In Python
Neat.  Works in Ruby, too.<p><pre><code>  def tree; Hash.new {|h, k| h[k] = tree }; end
  t = tree
  t[:foo][:bar] = "foobar"  # => {:foo=>{:bar=>"foobar"}}
</code></pre>
Probably more idiomatic to do it as a class, though.<p><pre><code>  class Tree < Hash
    def initialize
      super {|h,k|  h[k] = Tree.new }
    end
  end
</code></pre>
Btw.  How do you post nicely formatted code?<p>edit - Thanks!