I am trying to solve this problem:
Imagine a (literal) stack of plates. If the stack gets too high, it might topple. There- fore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOf- Stacks should be composed of several stacks, and should create a new stack once the previous one exceeds capacity. SetOfStacks.push() and SetOfStacks.pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack). Bonus: Implement a function popAt(int index) which performs a pop operation on a specific sub-stack.
So I wrote the code:
#!/bin/env python
from types import *
class Stack:
    def __init__(self):
        self.items = []
        self.capacity = 3
        self.stackscount = 0
    def create(self):
        id = self.stackscount + 1
        id = str(id) + "_stack"
        # How to create a new instance of Stack class at runtime ?
        # the __init__ must be run too.
    def push(self, item):
        if self.size() <= self.capacity:
            self.items.append(item)
        else:
            self.create()
    def pop(self):
        return self.items.pop()
    def popAt(self):
        pass
    def peek(self):
        return self.items[len(self.items)-1]
    def size(self):
        return len(self.items)
s = Stack()
s.push(10)
How do I create a new s type object dynamically at runtime?  I searched on the internet and found that using new.instance or new.classobj is the solution but when I did so my new object did not seem to have items from __init__ function. In python3, type() seems to be the answer but the docs doesn't have any examples.

SetOfStacks?SetOfStackscreates a newStackwhen the existing stacks are full.Stackis just responsible for refusing to accept any new items when full,SetOfStacksis responsible for creating additional space. Thecapacityshould be the capacity of eachStack, not the number of stacks in theSetOfStacks(which is initially one and will increase as necessary).__init__to containself.stacks = [Stack()](i.e. a list, currently containing a singleStack). Assumingcreatewould be called when the lastStackinself.stacksis full, it should.appenda newStack, not create a new list.