-
Notifications
You must be signed in to change notification settings - Fork 1
/
selection.py
138 lines (110 loc) · 3.95 KB
/
selection.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import time
def y_n_question(question):
while True:
# Ask question
answer = input(question)
answer_cleaned = answer[0].lower()
if answer_cleaned == 'y' or answer_cleaned == 'n':
if answer_cleaned == 'y':
return True
else:
return False
else:
print("Invalid input, please try again.")
def list_selection(list_in, note, type_in):
while True:
try:
print(note)
for j, i in enumerate(list_in):
print(str(j) + ": to select " + type_in + " [" + str(i) + "]")
column = list_in[int(input("Enter Selection: "))]
except ValueError:
print("Input must be integer between 0 and " + str(len(list_in)))
continue
else:
break
return column
def dict_selection(list_in, note, type_in):
while True:
try:
print(note)
for j, i in enumerate(list_in):
print(str(j) + ": to select " + type_in + " [" + str(i) + "]")
value = list(list_in)[int(input("Enter Selection: "))]
except ValueError:
print("Input must be integer between 0 and " + str(len(list_in)))
continue
else:
break
return value
def list_selection_multiple(list_in, note, type_in):
# Dedupe list_in
list_in = unique(list_in)
# Sort list_in
list_in.sort()
while True:
try:
print(note)
for j, i in enumerate(list_in):
print(str(j) + ": to include " + type_in + " [" + str(i) + "]")
# Ask for index list
list_index_string = input("Enter selections separated by spaces: ")
# Check if input was not empty
while not list_index_string:
list_index_string = input("Input was blank, please select " + type_in + " to include.")
time.sleep(3)
# Split string based on spaces
index_list = list_index_string.split()
# Get names of selections
name_list = list()
for i in index_list:
name_list.append(list_in[int(i)])
break
except:
print("An invalid input was detected, please try again.")
time.sleep(3)
continue
return name_list
def unique(items):
found = set([])
keep = []
for item in items:
if item not in found:
found.add(item)
keep.append(item)
return keep
def column_selection(headers, task):
while True:
try:
print("Select column.")
for j, i in enumerate(headers):
print(str(j) + ": to perform " + task + " on column [" + str(i) + "]")
column = headers[int(input("Enter Selection: "))]
except ValueError:
print("Input must be integer between 0 and " + str(len(headers)))
continue
else:
break
return column
def column_selection_multi(headers, task):
while True:
try:
print("Select column.")
for j, i in enumerate(headers):
print(str(j) + ": to perform " + task + " on column [" + str(i) + "]")
column_index_list_string = input("Enter Selections separated by spaces: ")
# Check if input was empty
while not column_index_list_string:
column_index_list_string = input("Input was blank, please select columns to include.")
# Split string based on spaces
column_index_list = column_index_list_string.split()
# Get column names list
column_name_list = list()
for i in column_index_list:
column_name_list.append(headers[int(i)])
except ValueError:
print("Input must be integer between 0 and " + str(len(headers) - 1))
continue
else:
break
return column_name_list