![](/img/trans.png)
[英]How to check if a cell of a Dataframe exists as a key in a dict, and if it does, check if another cell in same row exists in a list in a dict
[英]How to check if a key exists in mako dict?
假設我有以下情況:
mydict = {
a: 'A'
}
如何檢查字典中是否存在鍵a
? 偽代碼如下:
%if 'a' in mydict.keys()
${mydict['a']}
%endif
你可以使用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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.