Statement of Completion#9c215496
Python Collections
medium
Practice Python Lists with Students data
Resolution
Activities
Project.ipynb
Warm Up Activities¶
1. Find the Index of Pi
in a Given List¶
In [89]:
maths_constants = [['Euler Number', 2.7182],
['Golden Ratio', 1.618],
['Imaginary Unit', '1j'],
['Euler\'s identity', 'e^(iπ) + 1 = 0'],
['Phi', 1.618033988749895],
['Gamma Function', -0.08333333333333333],
['Pi'],
['Riemann Zeta Function', 1.202056903159594],
['Euler Formula', 'e^(ix) = cos(x) + i*sin(x)']
]
maths_constants
Out[89]:
[['Euler Number', 2.7182], ['Golden Ratio', 1.618], ['Imaginary Unit', '1j'], ["Euler's identity", 'e^(iπ) + 1 = 0'], ['Phi', 1.618033988749895], ['Gamma Function', -0.08333333333333333], ['Pi'], ['Riemann Zeta Function', 1.202056903159594], ['Euler Formula', 'e^(ix) = cos(x) + i*sin(x)']]
In [90]:
index_pi=maths_constants.index(["Pi"])
index_pi
Out[90]:
6
2. Insert the value 3.1416
after name Pi
in list of maths_constants
.¶
In [91]:
maths_constants[index_pi].insert(1,3.1416)
maths_constants
Out[91]:
[['Euler Number', 2.7182], ['Golden Ratio', 1.618], ['Imaginary Unit', '1j'], ["Euler's identity", 'e^(iπ) + 1 = 0'], ['Phi', 1.618033988749895], ['Gamma Function', -0.08333333333333333], ['Pi', 3.1416], ['Riemann Zeta Function', 1.202056903159594], ['Euler Formula', 'e^(ix) = cos(x) + i*sin(x)']]
3. Extend the list by adding all the elements from the given string¶
In [92]:
odd_list = [99,101,103,105,107,109]
even_string = '24689'
In [93]:
odd_list.extend(even_string)
odd_list
Out[93]:
[99, 101, 103, 105, 107, 109, '2', '4', '6', '8', '9']
4. Remove the last element from the list odd_list
¶
In [94]:
odd_list.remove("9")
odd_list
Out[94]:
[99, 101, 103, 105, 107, 109, '2', '4', '6', '8']
Student Data Activities¶
In [95]:
# Import the data from the text file into a list
student_list = []
with open("student.txt", "r") as file:
for line in file:
student = line.strip().split(',')
student_list.append(student)
# Print the first 5 students
student_list[:5]
Out[95]:
[['Gabriel', '53', '18', 'D', 'English'], ['Nora', '79', '18', 'F', 'Math'], ['Luna', '2', '18', 'A', 'English'], ['Anthony', '76', '18', 'A', 'Math'], ['Logan', '56', '17', 'D', 'History']]
5. How many students are there in our dataset student_list
?¶
In [96]:
len(student_list)
#print(f"The total number of students in the dataset is: {len(student_list)}")
Out[96]:
500
6. What's the name of the 400th student in our student_list
¶
In [97]:
#student_list[399]#gives you the whole row
student_list[399][0]
Out[97]:
'Lucas'
7. Check the correct age and subject of our student at 273rd index¶
In [98]:
#student_list[273]
age = student_list[273][2]
subject = student_list[273][4]
print(f"Age: {age} & subject: {subject}")
Age: 18 & subject: Science
8. Put the students from the index 98 to 214 into the list select_student
¶
In [99]:
select_student = student_list[98:214]
select_student
Out[99]:
[['Leah', '1', '17', 'F', 'Art'], ['Sophia', '39', '18', 'C', 'Geography'], ['Lucy', '106', '16', 'F', 'Science'], ['Liliana', '4', '17', 'F', 'Math'], ['Michael', '107', '17', 'A', 'English'], ['Charlotte', '14', '16', 'F', 'History'], ['David', '108', '17', 'C', 'Art'], ['Ethan', '109', '18', 'D', 'English'], ['James', '110', '16', 'C', 'English'], ['Zoe', '40', '16', 'F', 'Math'], ['Eleanor', '24', '17', 'C', 'Science'], ['Addison', '111', '18', 'F', 'History'], ['Benjamin', '112', '16', 'D', 'Geography'], ['Mia', '113', '18', 'E', 'History'], ['Abigail', '114', '16', 'F', 'Math'], ['Grace', '27', '17', 'C', 'History'], ['Caleb', '115', '18', 'F', 'Geography'], ['Zoey', '116', '18', 'C', 'Geography'], ['Emma', '117', '18', 'E', 'English'], ['Leo', '118', '18', 'E', 'Math'], ['Ethan', '119', '18', 'C', 'Science'], ['Hannah', '120', '17', 'A', 'English'], ['Brooklyn', '121', '16', 'C', 'Geography'], ['Dylan', '122', '18', 'C', 'History'], ['James', '123', '16', 'C', 'History'], ['Mia', '124', '16', 'E', 'Science'], ['Evelyn', '125', '17', 'C', 'Geography'], ['Maya', '126', '16', 'D', 'Geography'], ['Noah', '127', '18', 'C', 'Science'], ['David', '128', '16', 'F', 'Science'], ['Elijah', '129', '16', 'A', 'English'], ['Jackson', '130', '16', 'C', 'Math'], ['Lillian', '131', '16', 'B', 'English'], ['Lucas', '132', '18', 'E', 'History'], ['Logan', '133', '17', 'E', 'Science'], ['Zoey', '134', '16', 'B', 'Math'], ['Joseph', '135', '16', 'C', 'Math'], ['Nora', '136', '16', 'C', 'English'], ['Michael', '137', '16', 'A', 'Science'], ['Luna', '138', '16', 'A', 'Science'], ['Ethan', '139', '17', 'B', 'History'], ['Sarah', '140', '17', 'F', 'History'], ['Ethan', '141', '16', 'A', 'Science'], ['Stella', '142', '17', 'E', 'Art'], ['Grace', '143', '16', 'F', 'Geography'], ['Michael', '144', '17', 'C', 'Geography'], ['Emma', '145', '17', 'A', 'Math'], ['Daniel', '146', '18', 'C', 'Art'], ['Michael', '147', '16', 'A', 'Art'], ['Joseph', '148', '18', 'D', 'English'], ['Sophia', '149', '18', 'E', 'History'], ['Liliana', '150', '18', 'C', 'Math'], ['Michael', '151', '18', 'C', 'History'], ['Natalie', '152', '18', 'C', 'Art'], ['Maya', '153', '16', 'F', 'Math'], ['David', '154', '18', 'C', 'English'], ['Liam', '155', '18', 'F', 'History'], ['David', '156', '18', 'F', 'History'], ['Matthew', '157', '16', 'C', 'Art'], ['Ethan', '158', '18', 'E', 'Geography'], ['Benjamin', '159', '16', 'E', 'Geography'], ['Oliver', '160', '17', 'E', 'Math'], ['William', '161', '17', 'F', 'Geography'], ['Evelyn', '162', '18', 'B', 'English'], ['Sophia', '163', '18', 'D', 'Science'], ['Grace', '164', '17', 'C', 'History'], ['Liliana', '165', '17', 'D', 'Art'], ['Wyatt', '166', '16', 'D', 'Math'], ['Oliver', '167', '17', 'C', 'Geography'], ['Gabriel', '168', '18', 'D', 'Science'], ['Grace', '169', '17', 'B', 'Science'], ['Jack', '170', '18', 'A', 'Art'], ['Bella', '171', '16', 'E', 'English'], ['Layla', '172', '18', 'C', 'Science'], ['Leo', '173', '17', 'E', 'English'], ['Samuel', '174', '17', 'A', 'Science'], ['Eleanor', '175', '17', 'F', 'English'], ['Ava', '176', '16', 'B', 'Math'], ['Joseph', '177', '18', 'E', 'Science'], ['Maya', '178', '16', 'F', 'Science'], ['Leo', '179', '18', 'C', 'Science'], ['Maya', '180', '18', 'B', 'Math'], ['Benjamin', '181', '16', 'F', 'History'], ['Alexander', '182', '17', 'A', 'Math'], ['David', '183', '17', 'A', 'Science'], ['Aubrey', '184', '16', 'E', 'Math'], ['Caleb', '185', '16', 'F', 'Math'], ['Samuel', '186', '18', 'A', 'History'], ['Brooklyn', '187', '17', 'D', 'History'], ['Lily', '188', '16', 'B', 'Science'], ['Michael', '189', '16', 'B', 'English'], ['Scarlett', '190', '16', 'D', 'Geography'], ['Wyatt', '191', '17', 'C', 'History'], ['Eleanor', '192', '18', 'D', 'Math'], ['Bella', '193', '17', 'D', 'Math'], ['Evelyn', '194', '18', 'D', 'History'], ['Charlotte', '195', '18', 'B', 'Math'], ['Sarah', '196', '17', 'B', 'Math'], ['Audrey', '197', '18', 'C', 'Geography'], ['Lucas', '198', '17', 'A', 'History'], ['Penelope', '199', '18', 'B', 'Math'], ['Natalie', '200', '16', 'A', 'Math'], ['Jack', '201', '16', 'E', 'Geography'], ['Aiden', '202', '18', 'B', 'Math'], ['Chloe', '203', '18', 'A', 'Art'], ['Aubrey', '204', '18', 'D', 'History'], ['Sophia', '205', '18', 'C', 'History'], ['Ethan', '206', '17', 'A', 'Science'], ['Liliana', '207', '17', 'E', 'Art'], ['Bella', '208', '17', 'E', 'History'], ['Zoey', '209', '17', 'E', 'Math'], ['Alexander', '210', '17', 'C', 'Art'], ['Henry', '211', '17', 'E', 'Geography'], ['Alexander', '212', '18', 'A', 'Math'], ['Andrew', '213', '18', 'D', 'Math'], ['Audrey', '214', '17', 'E', 'History']]
9. Find the name, age, grade, subject
of the last student from our select_student
list.¶
In [100]:
name = select_student[-1][0]
age = select_student[-1][2]
grade = select_student[-1][3]
subject = select_student[-1][4]
print(f"name: {name} age: {age} grade: {grade} & subject: {subject}")
name: Audrey age: 17 grade: E & subject: History
List Iteration with Conditional Statements¶
10. Get the ages of each student and store it in the list students_age
¶
In [101]:
students_age = []
for student in student_list:
student_age=int(student[2])
students_age.append(student_age)
students_age
Out[101]:
[18, 18, 18, 18, 17, 18, 18, 17, 17, 18, 18, 18, 16, 17, 18, 16, 16, 16, 16, 16, 17, 17, 18, 18, 18, 17, 16, 17, 16, 16, 17, 18, 17, 17, 18, 17, 16, 18, 17, 18, 18, 16, 18, 16, 16, 18, 17, 18, 17, 17, 18, 16, 17, 17, 17, 17, 17, 18, 16, 17, 18, 18, 16, 17, 18, 16, 18, 18, 17, 18, 16, 18, 18, 18, 18, 16, 18, 17, 16, 17, 17, 16, 18, 16, 16, 17, 18, 16, 18, 17, 16, 16, 16, 16, 18, 18, 16, 18, 17, 18, 16, 17, 17, 16, 17, 18, 16, 16, 17, 18, 16, 18, 16, 17, 18, 18, 18, 18, 18, 17, 16, 18, 16, 16, 17, 16, 18, 16, 16, 16, 16, 18, 17, 16, 16, 16, 16, 16, 17, 17, 16, 17, 16, 17, 17, 18, 16, 18, 18, 18, 18, 18, 16, 18, 18, 18, 16, 18, 16, 17, 17, 18, 18, 17, 17, 16, 17, 18, 17, 18, 16, 18, 17, 17, 17, 16, 18, 16, 18, 18, 16, 17, 17, 16, 16, 18, 17, 16, 16, 16, 17, 18, 17, 18, 18, 17, 18, 17, 18, 16, 16, 18, 18, 18, 18, 17, 17, 17, 17, 17, 17, 18, 18, 17, 18, 18, 16, 18, 16, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 17, 17, 16, 18, 18, 18, 17, 16, 17, 17, 16, 17, 16, 16, 18, 16, 18, 18, 16, 16, 17, 17, 17, 18, 18, 18, 17, 18, 16, 17, 16, 18, 17, 16, 16, 17, 17, 18, 18, 18, 16, 16, 16, 18, 18, 16, 17, 18, 18, 18, 17, 17, 17, 16, 18, 17, 18, 17, 17, 18, 16, 17, 18, 17, 17, 16, 18, 16, 16, 16, 16, 18, 17, 17, 18, 16, 17, 18, 16, 17, 18, 16, 16, 16, 18, 17, 16, 18, 18, 16, 17, 18, 17, 17, 17, 17, 17, 18, 18, 17, 18, 16, 16, 17, 17, 17, 16, 17, 18, 18, 17, 18, 17, 16, 16, 18, 18, 16, 18, 17, 17, 18, 17, 18, 17, 16, 17, 17, 18, 16, 17, 16, 16, 18, 17, 18, 17, 16, 16, 16, 18, 17, 18, 18, 16, 16, 17, 17, 18, 16, 16, 18, 16, 17, 16, 18, 16, 16, 17, 17, 18, 18, 18, 17, 17, 16, 18, 17, 16, 16, 16, 16, 18, 16, 17, 17, 16, 17, 17, 17, 18, 17, 17, 17, 16, 18, 18, 16, 16, 17, 18, 17, 16, 16, 16, 18, 18, 18, 17, 17, 16, 18, 17, 18, 17, 16, 16, 17, 17, 17, 16, 18, 16, 17, 18, 16, 18, 17, 16, 16, 18, 18, 17, 18, 18, 16, 17, 17, 18, 17, 16, 16, 18, 18, 18, 18, 18, 16, 18, 18, 16, 18, 18, 17, 17, 18, 16, 17, 17, 18, 16, 16, 16, 18, 18, 17, 18, 18, 18, 17, 17, 18, 16, 16, 16, 17, 17, 16, 16, 17]
11. What is the average age of the students¶
In [102]:
average_age=sum(students_age)/len(students_age)
average_age
Out[102]:
17.048
12. How many students have History
as their favorite subject, how many have English
and how many have Math
¶
In [103]:
history_lovers_student = []
english_lovers_student = []
maths_lovers_student = []
for student in student_list:
if "History" in student[4]:
if student[0] not in history_lovers_student:
history_lovers_student.append(student[0])
if "English" in student[4]:
if student[0] not in english_lovers_student:
english_lovers_student.append(student[0])
if "Math" in student[4]:
if student[0] not in maths_lovers_student:
maths_lovers_student.append(student[0])
history_lovers = len(history_lovers_student)
english_lovers = len(english_lovers_student)
maths_lovers = len(maths_lovers_student)
print(f"History lovers: {history_lovers}")
print(f"English lovers: {english_lovers}")
print(f"Maths lovers: {maths_lovers}")
History lovers: 52 English lovers: 49 Maths lovers: 63
13. Separate all A
graders and all B
graders from the list student_list
¶
In [104]:
a_graders = []
b_graders = []
for student in student_list:
if student[3]=='A':
student_name = student[0]
student_age = student[2]
student_grade = student[3]
student_subject = student[4]
a_graders.append([student_name,student_age,student_grade,student_subject])
elif student[3]=='B':
student_name = student[0]
student_age = student[2]
student_grade = student[3]
student_subject = student[4]
b_graders.append([student_name,student_age,student_grade, student_subject])
#print(f"len a {len(a_graders)}, len b: {len(b_graders)}")the length
#print(f" a {(a_graders)}, b: {(b_graders)}")
print("A Graders:", a_graders)
print()
print("B Graders:", b_graders)
A Graders: [['Luna', '18', 'A', 'English'], ['Anthony', '18', 'A', 'Math'], ['Bella', '17', 'A', 'History'], ['Lucy', '17', 'A', 'History'], ['Brooklyn', '18', 'A', 'History'], ['Ava', '18', 'A', 'Art'], ['Riley', '17', 'A', 'Math'], ['Cameron', '16', 'A', 'Science'], ['Benjamin', '18', 'A', 'English'], ['Luke', '16', 'A', 'History'], ['Michael', '17', 'A', 'English'], ['Hannah', '17', 'A', 'English'], ['Elijah', '16', 'A', 'English'], ['Michael', '16', 'A', 'Science'], ['Luna', '16', 'A', 'Science'], ['Ethan', '16', 'A', 'Science'], ['Emma', '17', 'A', 'Math'], ['Michael', '16', 'A', 'Art'], ['Jack', '18', 'A', 'Art'], ['Samuel', '17', 'A', 'Science'], ['Alexander', '17', 'A', 'Math'], ['David', '17', 'A', 'Science'], ['Samuel', '18', 'A', 'History'], ['Lucas', '17', 'A', 'History'], ['Natalie', '16', 'A', 'Math'], ['Chloe', '18', 'A', 'Art'], ['Ethan', '17', 'A', 'Science'], ['Alexander', '18', 'A', 'Math'], ['Hannah', '18', 'A', 'English'], ['James', '18', 'A', 'Science'], ['Ethan', '17', 'A', 'English'], ['William', '17', 'A', 'Math'], ['Zoey', '17', 'A', 'Art'], ['Savannah', '17', 'A', 'Science'], ['Hannah', '18', 'A', 'Geography'], ['Emily', '17', 'A', 'Math'], ['Harper', '18', 'A', 'Science'], ['Owen', '16', 'A', 'Math'], ['Nora', '18', 'A', 'Art'], ['Joseph', '18', 'A', 'Math'], ['Nathan', '17', 'A', 'English'], ['Charlotte', '17', 'A', 'English'], ['Ava', '18', 'A', 'Math'], ['Elizabeth', '18', 'A', 'Math'], ['Noah', '17', 'A', 'Science'], ['Elizabeth', '16', 'A', 'Math'], ['Sophia', '18', 'A', 'History'], ['Dylan', '18', 'A', 'Math'], ['David', '17', 'A', 'Geography'], ['Amelia', '17', 'A', 'English'], ['Noah', '18', 'A', 'Math'], ['Grace', '16', 'A', 'English'], ['Hailey', '17', 'A', 'Science'], ['Wyatt', '18', 'A', 'Art'], ['Leah', '16', 'A', 'History'], ['David', '17', 'A', 'Math'], ['Abigail', '16', 'A', 'Geography'], ['Ethan', '16', 'A', 'Science'], ['Joseph', '17', 'A', 'History'], ['Sarah', '18', 'A', 'Math'], ['Lucas', '16', 'A', 'English'], ['Logan', '16', 'A', 'History'], ['Nora', '18', 'A', 'History'], ['Samuel', '16', 'A', 'English'], ['Michael', '16', 'A', 'Math'], ['Ethan', '18', 'A', 'Math'], ['Isaac', '17', 'A', 'Science'], ['Gabriel', '16', 'A', 'English'], ['Penelope', '17', 'A', 'Art'], ['Jacob', '18', 'A', 'Art'], ['Leah', '18', 'A', 'Art'], ['William', '16', 'A', 'Math'], ['Michael', '17', 'A', 'Math'], ['Benjamin', '16', 'A', 'Math'], ['Hannah', '18', 'A', 'Geography'], ['Ava', '16', 'A', 'Art'], ['Lillian', '17', 'A', 'Geography'], ['Olivia', '16', 'A', 'Geography'], ['Lillian', '17', 'A', 'Geography'], ['Ava', '17', 'A', 'English']] B Graders: [['Sarah', '17', 'B', 'History'], ['Savannah', '16', 'B', 'Geography'], ['Lily', '18', 'B', 'Art'], ['David', '17', 'B', 'History'], ['Hannah', '16', 'B', 'History'], ['Jacob', '18', 'B', 'Geography'], ['Alexander', '18', 'B', 'Math'], ['Brooklyn', '17', 'B', 'History'], ['Zoey', '17', 'B', 'Art'], ['Natalie', '16', 'B', 'Art'], ['Bella', '18', 'B', 'Art'], ['Lucy', '17', 'B', 'Math'], ['Cameron', '18', 'B', 'Geography'], ['Layla', '16', 'B', 'Science'], ['Layla', '17', 'B', 'English'], ['Victoria', '18', 'B', 'Art'], ['Scarlett', '16', 'B', 'Art'], ['Lillian', '16', 'B', 'Math'], ['Lillian', '16', 'B', 'English'], ['Zoey', '16', 'B', 'Math'], ['Ethan', '17', 'B', 'History'], ['Evelyn', '18', 'B', 'English'], ['Grace', '17', 'B', 'Science'], ['Ava', '16', 'B', 'Math'], ['Maya', '18', 'B', 'Math'], ['Lily', '16', 'B', 'Science'], ['Michael', '16', 'B', 'English'], ['Charlotte', '18', 'B', 'Math'], ['Sarah', '17', 'B', 'Math'], ['Penelope', '18', 'B', 'Math'], ['Aiden', '18', 'B', 'Math'], ['Maya', '16', 'B', 'English'], ['Olivia', '16', 'B', 'Science'], ['Charlotte', '17', 'B', 'Science'], ['Hannah', '16', 'B', 'Geography'], ['Elizabeth', '17', 'B', 'Geography'], ['James', '17', 'B', 'Science'], ['Madison', '16', 'B', 'English'], ['William', '18', 'B', 'Art'], ['Owen', '18', 'B', 'Science'], ['Andrew', '17', 'B', 'Science'], ['Samuel', '16', 'B', 'English'], ['Scarlett', '18', 'B', 'Science'], ['Nathan', '16', 'B', 'Math'], ['Hannah', '17', 'B', 'History'], ['Claire', '18', 'B', 'Science'], ['Olivia', '16', 'B', 'English'], ['Layla', '18', 'B', 'Science'], ['Elijah', '16', 'B', 'Science'], ['Mia', '17', 'B', 'Science'], ['Oliver', '17', 'B', 'Math'], ['Olivia', '16', 'B', 'History'], ['Benjamin', '17', 'B', 'Science'], ['Sarah', '16', 'B', 'English'], ['Benjamin', '16', 'B', 'Art'], ['Henry', '17', 'B', 'Art'], ['Jacob', '17', 'B', 'History'], ['Lucy', '18', 'B', 'Art'], ['Owen', '17', 'B', 'English'], ['Amelia', '18', 'B', 'History'], ['Daniel', '17', 'B', 'Science'], ['Nora', '17', 'B', 'History'], ['Leo', '18', 'B', 'History'], ['Hannah', '18', 'B', 'History'], ['Brooklyn', '16', 'B', 'History'], ['Isaac', '17', 'B', 'Geography'], ['Grace', '18', 'B', 'History'], ['Addison', '17', 'B', 'Geography'], ['John', '18', 'B', 'Geography'], ['Aiden', '18', 'B', 'History'], ['Harper', '18', 'B', 'Science'], ['Ethan', '18', 'B', 'Science'], ['William', '18', 'B', 'Art'], ['Sophia', '18', 'B', 'Math']]
14. Find the grade of a particular student.¶
In [105]:
for student in student_list:
if student[0] == 'Isaac' and student[2] == '16' and student[4] == 'Science':
print(student[3])
C
15. How many students are there whose name starts with the letter S
.¶
In [108]:
students_with_s = []
for student in student_list:
if student[0][0] == 'S':
students_with_s.append(student)
print(len(students_with_s))
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
16. How many students are under 17?¶
In [110]:
students_young=[]
for student in student_list:
if int(student[2])<17:
students_young.append(student)
print(len(students_young))
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
17. What is the minimum & maximum age of the students.¶
In [111]:
min_age = min(students_age)
max_age = max(students_age)
print(f"Min: {min_age}, Max: {max_age}")
Min: 16, Max: 18
18. Remove the student ['Luna', '18', 'E', 'Geography']
from the list student_list
.¶
In [117]:
student_to_remove = ['Luna', '18', 'E', 'Geography']
students_to_remove = []
for student in student_list:
if student[0] == student_to_remove[0] and student[2] == student_to_remove[1] and student[3] == student_to_remove[2] and student[4] == student_to_remove[3]:
students_to_remove.append(student)
print(students_to_remove)
for student in students_to_remove:
student_list.remove(student)
[]
19. Count the number of occurrences of the student in the student_list
¶
In [ ]:
student_to_count = ['Luna', '16']
count = 0
for student in student_list:
if student[0] == student_to_count[0] and student[2] == student_to_count[1]:
count += 1
print(count)