1

This is my code

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."


Deisred output setup: What's the best part about TCP jokes? punchline: I get to keep telling them until you get them.

6
  • do you want to print out the 'setup' and 'punchline' as well or just the sentences ? Commented Jan 4, 2020 at 8:28
  • 1
    Please include the desired output. Commented Jan 4, 2020 at 8:29
  • Please add more details in the question. How do you want your output to look like? Commented Jan 4, 2020 at 8:29
  • yes, I want to print the setup and punchline Commented Jan 4, 2020 at 8:29
  • 1
    If you don't want quotation marks and brackets, what are you converting it to JSON for? Maybe... don't do that? Commented Jan 4, 2020 at 8:30

1 Answer 1

1

Welcome to StackOverflow!

Here are the ingredients which will help you to accomplish this task:

Think about how you would output a single joke in l[0]. What's inside of l[0]['setup'] and what's inside of l[0]['punchline']?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.