简体   繁体   English

在Python中将两个列表合并后,如何从字典中获取键和值?

[英]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.

相关问题 python 从值列表中获取字典键 - python get dictionary key from value is list 将一个字典中的带有空列表的键与另一个包含该键作为值的字典合并后找到最小的集合 - Find the smallest set after merging key with empty list from one dictionary with another dictionary containing that key as value Python - 如何从列表中的字典 position 中获取键的值 - Python - How to get value of a key from position of dictionary inside a list 如何从列表中的键获取字典值? - How to get dictionary value from key in a list? 如何从字典Python列表中获取值? - How to get a value from a list of dictionary Python? 使用 Python 从字典列表中获取 N 个最大的键值 - Get the N largest key value from a list of dictionary with Python Python:当键是列表时从字典中获取值 - Python: get value from dictionary when key is a list 如何迭代字典中的列表,从键和 append 中获取值以列出? - How to iterate list in dictionary, get value from key and append to list? 如何在 Python 中的字典列表中使用另一个键列表中的值在字典中创建一个新键? - How to create a new key in dictionary with value from another key list from a list of dictionary in Python? 如何从两个列表构造字典,将该键映射到 python 值列表中相应索引处的值 - how to construct a dictionary from two lists mapping that key to the value at the corresponding index in the list of values in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM