Dynamic Image Variant in Template
So instead of using the dot syntax ., this would be a good place to use the subscript syntax [].

{# dot syntax #}
{{ foo.bar }}

{# subscript syntax #}
{{ foo['bar'] }}


When you use the subscript syntax to access a variable's attributes, you can safely use variables (by just removing the single quotes surrounding the attribute).

{% set bar = 'helloWorld' %}
{{ foo[bar] }}
{# functions just like foo.helloWorld #}


So for your example, you would do this:

{% if block.listImageRatio == '16by9' %}
    {% set imageRatio = 'imageVariants16by9' %}
{% endif %}

{% set optimizedImages = item.itemImage.one()[imageRatio] %}


(Twig docs)