简体   繁体   English

Python 字典每个键的多个值与 jinja2 迭代

[英]Python dictionary multiple values per key iterating with jinja2

I have a dictionary (created from a Pandas dataframe):我有一本字典(从 Pandas 数据框创建):

{'name': 'steve', 'info': [{'pipeline': 'product1, product2'}]}

and this is the jinja2 sintax in a.docx template:这是 a.docx 模板中的 jinja2 语法:

{% for x in info %} 
•   {{x[‘pipeline’]}}
{%endfor%}

the output is: output 是:

• product1, product2 • 产品 1、产品 2

but I'd like to have:但我想要:

• product1 • 产品 1

• product2 • 产品 2

I'm not able to iterate and separate the values of the "info" key.我无法迭代和分离“信息”键的值。

Seeing as the value of pipeline is a string you need to add info.split(',') to get [product1, product] as a list that you can iterate over由于管道的值是一个字符串,您需要添加 info.split(',') 以获得 [product1, product] 作为您可以迭代的列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM