How to change a list into list of lists

I’m using: SWI-Prolog version 8.4.3 for x64-win64

i have a list of patients :

PatientsList=[patient(204,4,2),patient(203,3,2),patient(304,8,3),patient(303,7,3),patient(404,12,4),patient(403,11,4),patient(504,16,5),patient(503,15,5)]

I want to have a separate list of lists depending on the third argument of each patient predicates

[ [patient(204,4,2),patient(203,3,2)] , [patient(304,8,3),patient(303,7,3)] , [patient(404,12,4),patient(403,11,4)] , [patient(504,16,5),patient(503,15,5)] ]

I found a function called singletons but it doesn’t do what i want.

Answered in Sorting predicates in PROLOG

1 Like