# How to change a list into list of lists

**URL:** <https://swi-prolog.discourse.group/t/how-to-change-a-list-into-list-of-lists/5637>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [July 31, 2022, 2:45am UTC](https://swi-prolog.discourse.group/t/how-to-change-a-list-into-list-of-lists/5637 "2022-07-31T02:45:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elfi](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@elfi](https://swi-prolog.discourse.group/u/elfi)\
**Post date:** [July 31, 2022, 2:45am UTC](https://swi-prolog.discourse.group/t/how-to-change-a-list-into-list-of-lists/5637/1 "2022-07-31T02:45:26Z")

</div>

I’m using: [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) version 8.4.3 for x64-win64

i have a list of patients :

```prolog
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

```prolog
[[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.

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [July 31, 2022, 1:22pm UTC](https://swi-prolog.discourse.group/t/how-to-change-a-list-into-list-of-lists/5637/2 "2022-07-31T13:22:25Z")

</div>

Answered in [Sorting predicates in PROLOG](https://swi-prolog.discourse.group/t/sorting-predicates-in-prolog/5618)
