Programmatically defined named expression for annotate_cols

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.

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:

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

Thank you!