This repository was archived by the owner on Oct 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.py
More file actions
executable file
·68 lines (48 loc) · 2.5 KB
/
lists.py
File metadata and controls
executable file
·68 lines (48 loc) · 2.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#------------------------------------------------------------------
# Libraries
#------------------------------------------------------------------
from csv import reader
#------------------------------------------------------------------
# Functions
#------------------------------------------------------------------
def make(coords, mols_list, size, path):
chapters = size * size
chapters_list = range(1, chapters + 1)
# Opens a new csv file and begins reading the contents
with open(path, newline="") as fopen:
csvreader = reader(fopen, delimiter=",")
# Skips headers and addes them to a list item
headers = next(csvreader)
# Holds all of the rows of prompts
prompts_list = []
for row in csvreader:
prompts_list.append(row)
# Creates a dictionary for referencing each chapter of lists
chapter_prompts = {i:[] for i in chapters_list}
# Iterates through each chapter index
for chapter in range(chapters):
# Adjusts the coodrinates format for use in indexing
x = coords[chapter][0] - 1
y = coords[chapter][1] - 1
# Iterates through each pair of entries of the prompts_list variable
for idx in range(int(len(prompts_list)/2)):
# Holds the current MOLS pairing in memory
current_mols_cell = mols_list[idx][x][y]
# Skips the first two row entries for the list title and id respectively
cell_x = current_mols_cell[0] + 2
cell_y = current_mols_cell[1] + 2
# Since prompts are collected two at a time, this variable temporarily holds them
row_pair = []
# Pulls the actuall row and all its contents into the row_pair variable
for row in prompts_list:
# Checks that the row ID matches the prompts index, matching rows are added to the list
if int(row[0]) == idx:
row_pair.append(row)
# Only two rows are added at a time, so this helps save a little bit of processing power and time
if len(row_pair) == 2:
break
prompt0 = dict({row_pair[0][1]: row_pair[0][cell_x]})
prompt1 = dict({row_pair[1][1]: row_pair[1][cell_y]})
chapter_prompts[chapter + 1].append(prompt0)
chapter_prompts[chapter + 1].append(prompt1)
return chapter_prompts