Enum within an enum

I believe that in Java, you can simply nest enums, as long as your non-enum constants come first. enum Action { FOO, BAR; enum MOVE { UP, DOWN, LEFT, RIGHT } } This compiles for me and gives me the behavior you were looking for.

Nested or Inner Class in PHP

Intro: Nested classes relate to other classes a little differently than outer classes. Taking Java as an example: Non-static nested classes have access to other members of the enclosing class, even if they are declared private. Also, non-static nested classes require an instance of the parent class to be instantiated. OuterClass outerObj = new OuterClass(arguments); … Read more

Checking a nested dictionary using a dot notation string “a.b.c.d.e”, automatically create missing levels

You could use an infinite, nested defaultdict: >>> from collections import defaultdict >>> infinitedict = lambda: defaultdict(infinitedict) >>> d = infinitedict() >>> d[‘key1’][‘key2’][‘key3’][‘key4’][‘key5’] = ‘test’ >>> d[‘key1’][‘key2’][‘key3’][‘key4’][‘key5’] ‘test’ Given your dotted string, here’s what you can do: >>> import operator >>> keys = “a.b.c”.split(“.”) >>> lastplace = reduce(operator.getitem, keys[:-1], d) >>> lastplace.has_key(keys[-1]) False You can … Read more