As far as I know, python list is a dynamic array. So when we reach a certain size, the capacity of that list will be increased automatically. But the problem is, unlike dynamic array of c or c++, even after increasing the capacity of list instance, the location is not being changed. Why is it happening? I’ve tested this using
Tag: dynamic-arrays
AssertEqual failing when comparing two seemingly identical IndexErrors
I have a DynamicArray class shown below. (I have only included relevant methods. The rest can be viewed from https://www.geeksforgeeks.org/implementation-of-dynamic-array-in-python/) Then I have another unit test file down below When I run the test I expect self.a.__getitem__(0) to throw IndexError(‘0 is out of bounds’) and I can’t see why the assertion fails? The only difference is that self.a.__getitem__(0) will yield
How do I get an empty list of any size in Python?
I basically want a Python equivalent of this Array in C: but in python I declare an array like: and the problem is I want to assign random slots with values like: but I can’t do that with Python, since the Python list is empty (of length 0). Answer If by “array” you actually mean a Python list, you can