magical expanding hash

Paul Rubin http
Wed Jan 18 00:03:41 CET 2006


"braver" <deliverable at gmail.com> writes:
> Can assigning to hash without intermediate levels, possibly adding to a
> numeric leaf or adding an element to a leaf array, be python code?
> 
> h['a']['b']['c'] += 42
> 
> If it can, I'd like to have a class which supports it.

Yes, it's simple enough to write a class like that.  What is your
purpose in asking someone else to write it for you?  If you're going
to write Python applications that use that class, you're going to have
to learn enough Python to easily write the class yourself.

> The multi-level hashes with default or accumulation come up naturally
> in text parsing.  Designing a dedicated class structure may or may not
> be a better choice, depending on expediency.

I understand that, I've written things like that in the past (not in
Python as it happens) and they were useful.



More information about the Python-list mailing list