在Python中,如何在没有引号和括号的情况下打印?
这是我的密码在Python中,如何在没有引号和括号的情况下打印?,python,json,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)) 去离子输出 设置:TCP笑话最好的部分是什么? 笑点:我会一直告诉他们直到你得到他们。欢迎来到StackOverflow 以下是帮助您完成此任务的要素: 知道 作用 for在列表
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))
去离子输出 设置:TCP笑话最好的部分是什么?
笑点:我会一直告诉他们直到你得到他们。欢迎来到StackOverflow 以下是帮助您完成此任务的要素:
- 知道
- 作用
在列表中循环for
l
考虑一下如何在
l[0]
中输出一个笑话。l[0]['setup']
和l[0]['punchline']
的内部是什么?您想同时打印“setup”和“punchline”还是只打印句子?请包括所需的输出。请在问题中添加更多详细信息。您希望您的输出是什么样子的?是的,我想打印设置和punchline如果您不需要引号和方括号,您将其转换为JSON的目的是什么?大概不要那样做?
{
"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."