> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/l/list_comprehensions.md).

# List comprehensions

```ruby
var n = 20
say gather {
    for x in (1 .. n) {
        for y in (x .. n) {
           for z in (y .. n) {
             take([x,y,z]) if (x*x + y*y == z*z)
           }
        }
    }
}
```

#### Output:

```
[[3, 4, 5], [5, 12, 13], [6, 8, 10], [8, 15, 17], [9, 12, 15], [12, 16, 20]]
```
