-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselection.py
80 lines (62 loc) · 2.07 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
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 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