<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def chained_set(self, value, command='set', *keys):
 """ 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] """

        new_object = self.__class__()
        existing = self
        for i in range(0, len(keys) - 1):
            if keys[i] in existing:
                existing = existing[keys[i]]
            else:
                existing[keys[i]] = new_object
                existing = existing[keys[i]]
        if command == 'set':
            existing[keys[len(keys) - 1]] = value
        elif command == 'append':
            if keys[len(keys) - 1] in existing:
                existing[keys[len(keys) - 1]].append(value)
            else:
                existing[keys[len(keys) - 1]] = [value]

        elif command == 'set_or_append':
            if keys[len(keys) - 1] in existing:
                if type(keys[len(keys) - 1]) == type([]):
                    existing[keys[len(keys) - 1]].append(value)
                else:
                    existing[keys[len(keys) - 1]] = [existing[keys[len(keys) - 1]], value]
            else:
                existing[keys[len(keys) - 1]] = value
        elif command == 'insert':
            if keys[len(keys) - 1] in existing:
                if not value in existing[keys[len(keys) - 1]]:
                    existing[keys[len(keys) - 1]].append(value)
            else:
                existing[keys[len(keys) - 1]] = [value]