-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcohort_data.py
More file actions
191 lines (130 loc) · 5.28 KB
/
Copy pathcohort_data.py
File metadata and controls
191 lines (130 loc) · 5.28 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# def split_file_contents(filepath):
# log_file = open(filepath)
# for line in log_file:
# line = line.strip()
# student_info = line.split("|")
# return student_info
def unique_houses(filename):
"""TODO: Create a set of student houses.
Iterates over the cohort_data.txt file to look for all of the included house names
and creates a set called 'houses' that holds those names.
ex. houses = set([ "Hufflepuff",
"Slytherin",
"Ravenclaw",
"Gryffindor",
"Dumbledore's Army",
"Order of the Phoenix"
])
"""
houses = set()
log_file = open(filename)
for line in log_file:
line = line.strip()
student_info = line.split("|")
if student_info[2] != "":
houses.add(student_info[2])
filename.close()
return houses
def sort_by_cohort(filename):
"""TODO: Sort students by cohort.
Iterates over the data to create a list for each cohort, ordering students
alphabetically by first name and tas separately. Returns list of lists.
ex. winter_15 = ["alice tsao", "amanda gilmore", "anne vetto", "..." ]
ex. all_students = [winter_15, spring_15, summer_15, tas]
"""
all_students = []
winter_15 = []
spring_15 = []
summer_15 = []
tas = []
advisor = set()
#checks to see if a student name is an advisor name, and if said student has a cohort (then they are probably a TA)
# First creat a set for a unique collection of advisor names
for line in filename:
line = line.strip()
student_info = line.split("|")
if student_info[3] != "":
advisor.add(student_info[3])
for line in filename:
line = line.strip()
student_info = line.split("|")
if student_info[1] in advisor:
tas.append(student_info[1])
# Code goes here
return all_students
def students_by_house(filename):
"""TODO: Sort students by house.
Iterate over the data to create a list for each house, and sort students
into their appropriate houses by last name. Sort TAs into a list called "tas".
Return all lists in one list of lists.
ex. hufflepuff = ["Gaikwad", "Le", "..." ]
ex. tas = ["Bryant", "Lefevre", "..."]
ex. houses_tas = [ hufflepuff,
gryffindor,
ravenclaw,
slytherin,
dumbledores_army,
order_of_the_phoenix,
tas
]
"""
all_students = []
gryffindor = []
hufflepuff = []
slytherin = []
dumbledores_army = []
order_of_the_phoenix = []
ravenclaw = []
tas = []
# Code goes here
return all_students
def all_students_tuple_list(filename):
"""TODO: Create a list of tuples of student data.
Iterates over the data to create a big list of tuples that individually
hold all the data for each person. (full_name, house, advisor, cohort)
ex. all_people = [
("Alice Tsao", "Slytherin", "Kristen", "Winter 2015"),
("Amanda Gilmore", "Hufflepuff", "Meggie", "Winter 2015"),
# ...
]
"""
student_list = []
# Code goes here
return student_list
def find_cohort_by_student_name(student_list):
"""TODO: Given full name, return student's cohort.
Use the above list of tuples generated by the preceding function to make a small
function that, given a first and last name, returns that student's cohort, or returns
'Student not found.' when appropriate. """
# Code goes here
return "Student not found."
##########################################################################################
# Further Study Questions
def find_name_duplicates(filename):
"""TODO: Using set operations, make a set of student first names that have duplicates.
Iterates over the data to find any first names that exist across multiple cohorts.
Uses set operations (set math) to create a set of these names.
NOTE: Do not include staff -- or do, if you want a greater challenge.
ex. duplicate_names = set(["Sarah"])
"""
duplicate_names = set()
# Code goes here
return duplicate_names
def find_house_members_by_student_name(student_list):
"""TODO: Create a function that prompts the user for a name via the command line
and returns everyone in their house that's in their cohort.
Use the list of tuples generated by all_students_tuple_list to make a small function that,
when given a student's first and last name, returns students that are in both that
student's cohort and that student's house."""
# Code goes here
return
#########################################################################################
#Here is some useful code to run these functions!
# all_students_data = all_students_tuple_list("cohort_data.txt")
# print all_students_data
# print unique_houses("cohort_data.txt")
# print sort_by_cohort("cohort_data.txt")
# print students_by_house("cohort_data.txt")
# print find_name_duplicates("cohort_data.txt")
# find_house_members_by_student_name(all_students_data)
# find_cohort_by_student_name(all_students_data)