[英]How to get key and value from a dictionary after merging it from two list in Python?
I have two list: 我有两个清单:
list_a = [<User: x>, <User: y>]
list_b = [False, True]
I want to create a dictionary by merging it. 我想通过合并来创建字典。 I did by the following code:
我是通过以下代码完成的:
details = dict(zip(list_a,list_b))
But i am not able solve the issue how to get the value in a template. 但是我无法解决如何在模板中获取价值的问题。
In my template code: 在我的模板代码中:
{% for x in details %}
{{ }}
{{ }}
{ % endfor %}
I have these two vacant tag in template. 我的模板中有这两个空缺标签。 I want to put it as follow:
我想说如下:
for the first iteration, 在第一次迭代中
{{ x }}
{{ False}}
for second iteration, 对于第二次迭代,
{{ y }}
{{ True}}
..and so on ..等等
{% for key, value in details.iteritems %}
{{ key }}
{{ value }}
{ % endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.