-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreformat.py
75 lines (51 loc) · 1.6 KB
/
reformat.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def combineArgs(lst:list,argument:int):
temp = []
for i in range(len(lst)):
temp.append(lst[i][argument])
return temp
def lst2str(superlist:list):
rawArgs = superlist
groupedArgs = []
zippedArgs = []
rnge = len(superlist[0])
# grab all related arguments `i` from each sublist of rawArgs, add to a new sublist in groupedArgs
for i in range(len(rawArgs[0])):
groupedArgs.append(combineArgs(rawArgs,i))
# convert all list items to strings
for i in range(len(groupedArgs)):
for j in range(len(groupedArgs[0])):
groupedArgs[i][j] = str(groupedArgs[i][j])
# combine each sublist of related arguments into one string separated by a comma
for i in range(len(groupedArgs)):
zippedArgs.append(','.join(groupedArgs[i]))
return zippedArgs
def dic2lstlst(dic:bool):
keys = list(dic.keys())
values = list(dic.values())
return list(map(list, zip(keys, values)))
def prettyDic(dic:dict, new:bool):
lstlst = dic2lstlst(dic)
out = []
for i in range(len(lstlst)):
temp = []
temp.append(str(lstlst[i][0]))
temp.append(" = ")
temp.append(str(lstlst[i][1]))
out.append(''.join(temp))
out = '\n'.join(out)
if new == True:
return ''.join(['\nNew settings: \n', out])
else:
return ''.join(['\nCurrent settings: \n', out])
def allStr(lst):
if type(lst) != list:
if type(lst) == dict:
raise TypeError('Function reformat.allStr does not accept dictionaries, but was given one.')
lst = [lst]
for i in range(len(lst)):
lst[i] = str(lst[i])
return lst
def assemble(options:list, settings:list):
for i in range(len(settings)):
options[i*2+1] = settings[i]
return options