如何在Python中不带引号和括号的情况下打印此内容?

时间:2020-01-04 08:25:42

标签: python json

这是我的代码

keys = {"setup", "punchline"}

l = [{k:v for k, v in i.items() if k in keys} for i in response_dict]


print(json.dumps(l, indent=4, sort_keys=False))
    {
        "setup": "What's the best part about TCP jokes?",
        "punchline": "I get to keep telling them until you get them."
    },
    {
        "setup": "How many programmers does it take to change a lightbulb?",
        "punchline": "None that's a hardware problem"
    },
    {
        "setup": "What's the best thing about a Boolean?",
        "punchline": "Even if you're wrong, you're only off by a bit."


期望的输出 设置:关于TCP笑话的最好之处是什么? 要点:我要不断告诉他们,直到你明白为止。

1 个答案:

答案 0 :(得分:1)

欢迎使用StackOverflow!

以下是可以帮助您完成此任务的成分:

考虑如何在l[0]中输出一个笑话。 l[0]['setup']内部是什么,l[0]['punchline']内部是什么?