'how can i retreive information from nested list prolog

If I have a nested list like that

students = [[student01,'math',55],[student01,'programing',80],[student02,'math',90],...]

and I want to write predict ( without using built in functions ) to retreive the name and grade of specific course.

example: studentInCourse('math',students).

sol: students = [[student01,55],[student02,90]]

I tried :

 studentInCourse(Course,students):-
       studentInCourse([F,C,Z]|T,C,[F,Z]),
       studentInCourse(T,C,[F,Z].

I know it's propably wrong because it's my first time in this language



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source