# Apply a list of parameters to a list of input

**URL:** <https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [June 7, 2023, 3:44pm UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894 "2023-06-07T15:44:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![powerpeanuts1](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@powerpeanuts1](https://forum.kx.com/u/powerpeanuts1)\
**Post date:** [June 7, 2023, 3:44pm UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894/1 "2023-06-07T15:44:00Z")

</div>

Hi, I have a simple question:

I have a list&nbsp;b:(1 5 6;9 10 76; 43 12 11) and I would like to take the nth indexed element from each list where n is a list, for example&nbsp;n = (0;2;1).

So the output should be (1;76;12).

&nbsp;

What is the easiest syntax to do it? Thanks.

&nbsp;

---

<div class="post-metadata">

**Author:** ![eohara\_kdb1](https://avatars.discourse-cdn.com/v4/letter/e/46a35a/32.png) [@eohara\_kdb1](https://forum.kx.com/u/eohara_kdb1)\
**Post date:** [June 7, 2023, 3:50pm UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894/2 "2023-06-07T15:50:00Z")

</div>

Here’s one option:

&nbsp;

&nbsp;

q)b:(1 5 6;9 10 76; 43 12 11) q)n:(0;2;1) q){x y}'[b;n] 1 76 12

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![eohara\_kdb1](https://avatars.discourse-cdn.com/v4/letter/e/46a35a/32.png) [@eohara\_kdb1](https://forum.kx.com/u/eohara_kdb1)\
**Post date:** [June 7, 2023, 4:19pm UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894/3 "2023-06-07T16:19:00Z")

</div>

As far as I know it’s not possible without some kind of each, so here’s the same approach for a table:

q)tab:([time:10:03:54.347 10:04:05.827]price:(20.83 21.44 26.83 29.83e;88.88 88.75 83.27 823.77f);n:0 1) q)update m:{x y}'[price;n] from tab time | price n m ------------| --------------------------------- 10:03:54.347| 20.83 21.44 26.83 29.83 0 20.83e 10:04:05.827| 88.88 88.75 83.27 823.77 1 88.75

&nbsp;

---

<div class="post-metadata">

**Author:** ![rocuinneagain1](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@rocuinneagain1](https://forum.kx.com/u/rocuinneagain1)\
**Post date:** [June 7, 2023, 4:27pm UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894/4 "2023-06-07T16:27:00Z")

</div>

q)b@'(0;2;1) 1 76 12

---

<div class="post-metadata">

**Author:** ![cillianreilly1](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@cillianreilly1](https://forum.kx.com/u/cillianreilly1)\
**Post date:** [June 8, 2023, 12:09am UTC](https://forum.kx.com/t/apply-a-list-of-parameters-to-a-list-of-input/12894/5 "2023-06-08T00:09:00Z")

</div>

The lambda isn’t necessary here:

&nbsp;

q)update m:price@'n from tab time | price n m ------------| --------------------------------- 10:03:54.347| 20.83 21.44 26.83 29.83 0 20.83e 10:04:05.827| 88.88 88.75 83.27 823.77 1 88.75

&nbsp;

Not useful for the general case, but here you can forgo the explicit n column and use the virtual index column instead:

&nbsp;

q)tab:([time:10:03:54.347 10:04:05.827]price:(20.83 21.44 26.83 29.83e;88.88 88.75 83.27 823.77f)) q)update m:price@'i from tab time | price m ------------| ------------------------------- 10:03:54.347| 20.83 21.44 26.83 29.83 20.83e 10:04:05.827| 88.88 88.75 83.27 823.77 88.75

&nbsp;
