-
Notifications
You must be signed in to change notification settings - Fork 0
/
L2_14.py
46 lines (34 loc) · 1.27 KB
/
L2_14.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
class MyPowerList:
def __init__(self, initialList=[]):
if type(initialList) is list:
self.pList = initialList
else:
raise ValueError("Constuctor parameter is not a list")
'''def addItem(self, item):
self.pList.append(item)
def removeItem(self, index):
try:
del(self.pList[index])
except Exception as e:
print("Couldn't delete item: "+str(e))
def sort(self):
for x in range(len(self.pList)):
current = self.pList[x]
index = x
while index > 0 and self.pList[index - 1] > current:
self.pList[index] = self.pList[index - 1]
index = index-1
self.pList[index] = current
def lMerge(self, mergeList):
self.pList = mergeList+self.pList
def rMerge(self, mergeList):
self.pList = self.pList+mergeList
def writeToFile(self, path):
with open(path, 'w') as f:
for item in self.pList:
f.write("%s " % item)'''
def readFromFile(self, path):
with open(path, 'r') as f:
self.pList = list(map(lambda x: int(x), f.read().split()))
def printList(self):
print(self.pList)