Is there an equivalent syntax in Jinja2 to a Python list comprehension? For example how to implement the following?:
['dash' if s == '-' else 'dot' for s in '---..---']
(Result):
['dash', 'dash', 'dash', 'dot', 'dot', 'dash', 'dash', 'dash']
Is there an equivalent syntax in Jinja2 to a Python list comprehension? For example how to implement the following?:
['dash' if s == '-' else 'dot' for s in '---..---']
(Result):
['dash', 'dash', 'dash', 'dot', 'dot', 'dash', 'dash', 'dash']
There’s perhaps a better option, but this works…
{{ '---..---' | list | replace('-', 'dash') | replace('.', 'dot') }}