def chained_set(self, value, command='<STR_LIT>', *keys):
new_object = self.__class__()<EOL>existing = self<EOL>for i in range(<NUM_LIT:0>, len(keys) - <NUM_LIT:1>):<EOL><INDENT>if keys[i] in existing:<EOL><INDENT>existing = existing[keys[i]]<EOL><DEDENT>else:<EOL><INDENT>existing[keys[i]] = new_object<EOL>existing = existing[keys[i]]<EOL><DEDENT><DEDENT>if command == '<STR_LIT>':<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]] = value<EOL><DEDENT>elif command == '<STR_LIT>':<EOL><INDENT>if keys[len(keys) - <NUM_LIT:1>] in existing:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]].append(value)<EOL><DEDENT>else:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]] = [value]<EOL><DEDENT><DEDENT>elif command == '<STR_LIT>':<EOL><INDENT>if keys[len(keys) - <NUM_LIT:1>] in existing:<EOL><INDENT>if type(keys[len(keys) - <NUM_LIT:1>]) == type([]):<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]].append(value)<EOL><DEDENT>else:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]] = [existing[keys[len(keys) - <NUM_LIT:1>]], value]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]] = value<EOL><DEDENT><DEDENT>elif command == '<STR_LIT>':<EOL><INDENT>if keys[len(keys) - <NUM_LIT:1>] in existing:<EOL><INDENT>if not value in existing[keys[len(keys) - <NUM_LIT:1>]]:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]].append(value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>existing[keys[len(keys) - <NUM_LIT:1>]] = [value]<EOL><DEDENT><DEDENT>
chained_set takes the value to
enter into the dictionary, a command of what
to do with the value, and a sequence of keys.

Examples:

d = {}

d.chained_set(1,'append','level 1','level 2')

-> d['level 1']['level 2'] = [1]

d.chained_set(2,'append','level 1','level 2')

-> d['level 1']['level 2'] = [1,2]