How to implement an array data structure from scratch in python?

Viewed 708

I've used arrays in python (both as list and array.array) but I was wondering how can I implement a data structure like an array in Python. The following is my implementation after looking at implementations done in other languages. Please let me know of improvements.

class my_array:
    def __init__(self, length):
        self.length = length
        self.data = {}

    def get(self, index):
        return self.data[index]
    
    def push(self, item):
        self.data[self.length] = item
        self.length += 1
        return self.data
    
    def pop(self):
        last_item = self.data[self.length - 1]
        del self.data[self.length-1]
        self.length -= 1
        return last_item
    
    def insert(self, index, item):
        self.data[index] = item
0 Answers
Related