Jun-13-2020, 01:50 PM
# list of dictionary
students = [{'id': '001', 'name': 'John'},
{'id': '100', 'name': 'Park'},
{'id': '010', 'name': 'Bjarne'}
]
# removing student who's name is Park in students list
def erase_student(key, val):
for student in students:
if student[key] == val:
students.remove(student)
erase_student('name', 'Bjarne')I want to replace for statement to code like this:student = student in students if student[key] == value students.remove(student)But I can't make proper shorter code.
I'll be thankful if you give me advice.
