# Dictionaries: Select where statement

**URL:** <https://swi-prolog.discourse.group/t/dictionaries-select-where-statement/4929>\
**Category:** Help!\
**Tags:** how-to, dicts\
**Created:** [January 23, 2022, 9:47am UTC](https://swi-prolog.discourse.group/t/dictionaries-select-where-statement/4929 "2022-01-23T09:47:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Losbarthos](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/losbarthos/32/4037_2.png) [@Losbarthos](https://swi-prolog.discourse.group/u/Losbarthos)\
**Post date:** [January 23, 2022, 9:47am UTC](https://swi-prolog.discourse.group/t/dictionaries-select-where-statement/4929/1 "2022-01-23T09:47:41Z")

</div>

I have some dictionary (based on this [introduction](https://www.swi-prolog.org/pldoc/man?section=bidicts)), say

`test{'Key 1':111, 'Key 2':12, 'Key 3':12, 'Key 4':72, 'Key 5':55}`

My aim now is to create some (sub)dictionary, where all Values have some property X (e.g. value is greater than 33). Say I want to build some function in which I can make some select where statement. In the tutorial above I only found select statements.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 23, 2022, 10:35am UTC](https://swi-prolog.discourse.group/t/dictionaries-select-where-statement/4929/2 "2022-01-23T10:35:43Z")

</div>

The typical route for operations that filter/map/… a whole dict is to use dict\_pairs/3, use the well known list operations and then again dict\_pairs/3 to create a new dict. This is also the efficient route as dict modifications are all O(n) where n is the number of keys. Although the constant factor is low (often just copying an array), many modifications to a dict step-by-step create a lot of garbage dicts that (often) need to be garbage collected some day.
