I have a list of integers stored in a list. Apparently it is stored as string in the datastore. So my current list of integers are as:
price = ['31412', '12300', '23000']
I want to get the highest number from the list.
{% for i in price %}
highest price is: {{ i | max }}
{% endfor %}
Expected output:
highest price is: 31412
What I get is:
highest price is: 4
How can I do this correctly?
>Solution :
You need to first convert each string in the list to an integer before finding the maximum.
According to my understanding of the documentation you should be able to use the map filter like so:
highest price is: {{ price | map('int') | max }}
This should be equivalent to the Python code max(map(int, price)).
You don’t need a for construct. The max filter already implicitly loops over the price list.