from copy import deepcopy

class IModel():
    def __init__(self):
        self.list = []

    def __getitem__(self, index):
        '''
        Getter for the [] operator

    def __setitem__(self, index, value):
        '''
        Setter for the [] operator
        '''
        self.list[index] = value

    def extend(self, val):
        self.list.extend([0] * val)

    def append(self, val):
        self.list.append(val)

    def __iter__(self):
        i = 0
        while i < len(self.list):
            yield self.list[i]
            i += 1

    def __len__(self):
        return len(self.list)

    def __delitem__(self, index):
        del self.list[index]
        return

def gnomeSort(list):
    i = 0
    n = len(list)
    cpy = deepcopy(list)
    while i < n:
        if i and cpy[i] < cpy[i-1]:
            cpy[i], cpy[i-1] = cpy[i-1], cpy[i]
            i -= 1
        else:
            i += 1
    return cpy

def _filter(list, f):
    result = []
    for e in list:
        if f(e):
            result.append(e)
    return result

if __name__ == "__main__":
    a = IModel()
    a.extend(4)
    print(a.list)
    a[0] = 15
    a[1] = 10
    a[2] = 5
    a[3] = 3
    for i in a:
        print(i)
    print("-----------")
    for i in gnomeSort(a):
        print(i)
    print("-----------")
    for i in _filter(a, lambda x: x % 5):
        print(i)
        '''
        if index >= len(self.list):
            raise IndexError("Index out of range.")
        return self.list[index]
