<div class="gmail_quote">On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha <span dir="ltr"><<a href="mailto:pavpanchekha@gmail.com">pavpanchekha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I want a dictionary that will transparently "inherit" from a parent<br>
dictionary. So, for example:<br>
<br>
"""<br>
a = InheritDict({1: "one", 2: "two", 4: "four"})<br>
b = InheritDict({3: "three", 4: "foobar"}, inherit_from=a)<br>
<br>
a[1] # "one"<br>
a[4] # "four"<br>
b[1] # "one"<br>
b[3] # "three"<br>
b[4] # "foobar"<br>
"""<br>
<br>
I've written something like this in Python already, but I'm wondering<br>
if something like this already exists, preferably written in C, for<br>
speed.</blockquote><div><br>Why complicate this with a custom object? Just use regular dicts and make b a copy of a.<br><br>a = {1: 'one', 2: 'two', 4: 'four'}<br>b = dict(a)<br>b[3] = 'three'<br>
b[4] = 'foobar'<br></div></div>