-
Notifications
You must be signed in to change notification settings - Fork 19
/
dynamic_array.py
53 lines (39 loc) · 1.45 KB
/
dynamic_array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Модуль "заглушка" для тестов"""
from array import array
class Array:
"""Массив"""
def __init__(self, typecode, initializer):
self.typecode = typecode
self.my_array = initializer
def append(self, item):
"""Добавление элемента"""
if self.typecode == 'd':
self.my_array.append(float(item))
else:
self.my_array.append(int(item))
def insert(self, index, item):
"""Операция вставки"""
if self.typecode == 'd':
self.my_array.insert(index, float(item))
else:
self.my_array.insert(index, int(item))
def remove(self, item):
"""Операция удаления"""
self.my_array.remove(item)
def pop(self, index):
"""Операция удаления с возвратом"""
return self.my_array.pop(index)
def __getitem__(self, index):
return self.my_array[index]
def __setitem__(self, index, value):
self.my_array[index] = value
def __reversed__(self):
return self.__class__(self.typecode, list(reversed(self.my_array)))
def __len__(self):
return len(self.my_array)
def __sizeof__(self):
return self.my_array.__sizeof__()
def __eq__(self, o: object):
if isinstance(o, array):
return o.typecode == self.typecode and list(o) == self.my_array
return False