gpt4 book ai didi

Python 将字典嵌套到 reStructuredText 项目符号列表中

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:07 24 4
gpt4 key购买 nike

我有这本字典:

d = {'B': {'ticket': ['two', 'three'], 'note': ['nothing to report']}, 'A': {'ticket': ['one'], 'note': ['my note']}, 'C': {'ticket': ['four'], 'note': ['none']}}

我正在尝试将其转换为 .rst 文档作为项目符号列表,例如:

* A

* ticket:

* one

* note

* my note

* B

* ticket:

* two
* three

* note:

* nothing to report

* C

* ticket:

* four

* note:

* none

我读了this approach但我无法将其翻译成项目符号列表

感谢大家

最佳答案

对于像你的具体例子这样的东西,这个怎么样:

>>> for key, value in d.items():
... print('* {}'.format(key))
... for k, v in value.items():
... print(' * {}:'.format(k))
... for i in v:
... print(' * {}'.format(i))
...
* B
* note:
* nothing to report
* ticket:
* two
* three
* A
* note:
* my note
* ticket:
* one
* C
* note:
* none
* ticket:
* four

关于Python 将字典嵌套到 reStructuredText 项目符号列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com