Say if I have the following:
mydict = { a: 'A' }
How do I check if key a exists in the dictionary? Pseudocode below:
a
%if 'a' in mydict.keys() ${mydict['a']} %endif
You can just use in:
in
from mako.template import Template t = Template(""" % if key in d: key is in dictionary % else: key is not in dictionary % endif """) print t.render(key='a', d={'a': 'A'}) # prints "key is in dictionary"
Copyright © 2021 Jogjafile Inc.
You can just use
in
: