i'm try to do smthing like this:
{% for i in list %} <td style="background-color: {{color_rule|get_item:i}}">{{i}}</td> {% endfor %}
where:
def get_item(dictionary, key): return dictionary.get(key)
please help
CodePudding user response:
According to the documentation.
{% for key, i in list.items %}
{{ key }}: {{ i}}
{% endfor %}
CodePudding user response:
The dictionary keys are lower case letters but the list are all uppercase - keys are case sensitive so nothing is being returned. Change your list to all lower case or your dict keys to uppercase and it will work.
Referring to the comment with additional context:
color_rules = {
'c':'rgb(87,213,255)',
'a':'rgb(182,83,248)',
'g':'rgb(163,196,60)',
't':'rgb(243, 100, 96)',
},
list = "CAGCCAGACCACAGGCCAGACATGACGTGGAGGCAAGCGGCCACAACGTGGAGGTGGA"
As an aside, you should avoid naming variables with python functions, i.e. list()
- also the list isn't actually a list but a string. Something like color_string
would be more appropriate.