Only after the@AndersonCarlosWoss identified that there was another identical question, I saw that his answer is much wider than mine. See /a/190086/64969
Use list comprehension
Be it sala
a student list. Be a student defined as having the attribute nota
. Be it corte
the variable of the cutting bike. Then we can get the list of approved students as follows:
aprovados = [ aluno for aluno in sala if aluno.nota >= corte ]
Thus, we get the list of approved students from a room without having to change the original value of the room list.
EDIT
My initial reading of the problem was that one had a list of students that needed to be filtered by note, but rereading the issue and, also, taking into account the comment of the AP, I realized that one has a banknote. My previous code remains valid, but we need to review some of the concepts used.
As we are with a list of notes, I have no object aluno
attribute-ridden nota
, only a number that already indicates the student’s grade. Thus:
Be it sala
a list of student grades. Be corte
the variable of the cutting bike. Then we can get the list of approved students as follows:
notas_aprovadas = [ nota for nota in sala if nota >= corte ]
Show what you’ve done and what you’re having trouble with, specify your question and remember that Stackoverflow is not a place to ask people to do college/college "homework".
– Gabriel Belini
@Jeffersonquesado the title is almost the same, but the problems are different.
– Daniel
@Danielgomes true, I falter my. This one can go with
list comprehension
– Jefferson Quesado