# Programmatically defined named expression for annotate\_cols

**URL:** <https://discuss.hail.is/t/programmatically-defined-named-expression-for-annotate-cols/1304>\
**Category:** Hail Query & hailctl\
**Created:** [February 21, 2020, 8:43am UTC](https://discuss.hail.is/t/programmatically-defined-named-expression-for-annotate-cols/1304 "2020-02-21T08:43:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FFS](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ffs/32/496_2.png) [@FFS](https://discuss.hail.is/u/FFS)\
**Post date:** [February 21, 2020, 8:43am UTC](https://discuss.hail.is/t/programmatically-defined-named-expression-for-annotate-cols/1304/1 "2020-02-21T08:43:15Z")

</div>

Is it possible to create named expressions to use in annotate\_cols programmatically?

Something along the lines:

```
for i in range(10):
    mt = mt.annotate_cols(f'variable_{i}' = mt.variable == i)

```

This could be neat for quick [one-hot encoding of categorical variables](https://discuss.hail.is/t/categorical-covariates-in-association-analyses/399).

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [February 21, 2020, 11:35am UTC](https://discuss.hail.is/t/programmatically-defined-named-expression-for-annotate-cols/1304/2 "2020-02-21T11:35:11Z")

</div>

Yes! This involves a python trick. In Python, you can pass any dictionary as a set of keyword arguments with a special syntax, `**`. So we can do:

```auto
mt = mt.annotate_cols(**{f'variable_{i}': mt.variable==i for i in range(10)})

```

---

<div class="post-metadata">

**Author:** ![FFS](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ffs/32/496_2.png) [@FFS](https://discuss.hail.is/u/FFS)\
**Post date:** [February 24, 2020, 9:18am UTC](https://discuss.hail.is/t/programmatically-defined-named-expression-for-annotate-cols/1304/3 "2020-02-24T09:18:05Z")

</div>

Thank you!
