This repository was archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (43 loc) · 1.58 KB
/
utils.py
File metadata and controls
53 lines (43 loc) · 1.58 KB
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
def print_inline_list(target_list):
"""
Print in the same line the elements of a list
:param target_list: the list with the elements
:return: None
"""
for item in target_list:
chunk = "'" + str(item) + "',"
print(chunk, end=' ')
def print_format_matrix(matrix):
"""
Print a matrix in a organized way using the function print_inline_list
:param matrix: the target matrix
:return: None
"""
for row in matrix:
print_inline_list(row)
print("\n")
def transpose_matrix(matrix):
"""
Transpose a matrix
:param matrix: target matrix
:return: result matrix
"""
result_matrix = [[None for col in range(len(matrix))] for row in range(len(matrix[0]))]
for i in range(len(matrix)):
for j in range(len(matrix[0])):
result_matrix[j][i] = matrix[i][j]
print_format_matrix(result_matrix)
return result_matrix
def get_matrix_for_response(matrix, default_null=None):
"""
It return a matrix that is a list of list, instead a list o Frames()
:param default_null: The default value for null spaces. For example could be " " or -1
:param matrix: list o of list of Frames()
:return: list of lists of integers
"""
list_of_lists = [[" " for col in range(len(matrix[0]))] for row in range(len(matrix))]
for row_index, row in enumerate(matrix):
for item_index, item in enumerate(row):
primitive = item.get_content(default=default_null)
list_of_lists[row_index][item_index] = primitive
return list_of_lists