-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw4.py
61 lines (51 loc) · 1.35 KB
/
hw4.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
54
55
56
57
58
59
60
61
# collaborators: Linh Nguyen
# #### Problem 1 #######
# Answer
def indexes(wo, c):
wordL = []
for i, s in enumerate(wo):
if c in s:
wordL.append(int(i))
return wordL
# #### Problem 2 #######
# Answer
def hasLetterCount(lst, numChar):
wrd = []
for h in lst:
j = len(h)
if j == numChar:
wrd.append(h)
return wrd
# #### Problem 3 #######
# Answer
def intersect(lst1, lst2):
wrd = []
for i in lst1:
for j in lst2:
if i == j:
k = i = j
if k not in wrd:
wrd.append(k)
print(wrd)
# #### Problem 4 #######
# Answer
def describe(v):
lst=[len(i) for i in v]
if(len(set(lst))) > 1:
return 'Invalid'
if (len(lst)==lst[0]):
return 'Square'
else:
return 'Rectangular'
# #### Problem 5 #######
# reference: https://snakify.org/en/lessons/two_dimensional_lists_arrays/
# reference: https://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists/11520540
# Answer
def identityMatrix(rank):
sLst: List[List[int]] = [[0 for x in range(rank)] for y in range(rank)]
for i in range(rank):
sLst[i][i] = 1
return sLst
if __name__ == '__main__':
import doctest
print(doctest.testfile('hw4_test.py', verbose=False))