I have the follow JSON as an output of an enumerate function.
{'question': (0, 'Who invented the light bulb?'), 'answers': [{'answer': 'Thomas Edison', 'score': '2.0'}, {'answer': 'Nikola Tesla', 'score': '2.0'}, {'answer': 'Albert Einstein', 'score': '0.0'}], 'error': "We didn't quite get that"}
How can I remove the 0 and the enclosing bracket so it looks like this.
{'question': 'Who invented the light bulb?', 'answers': [{'answer': 'Thomas Edison', 'score': '2.0'}, {'answer': 'Nikola Tesla', 'score': '2.0'}, {'answer': 'Albert Einstein', 'score': '0.0'}], 'error': "We didn't quite get that"}
I’d appreciate any python or Regex solution. Thank you.
4
Answers
I just found out that I could simply use an underscore (_) for my enumerate counter to show that I won't use the variable.
Like so:
I had initially used:
but a Ruff linter in the repository I needed to push the code to kept raising issues with
i
not being used.if you simply want to replace the brackets and the 0 with nothing you can do:
You don’t show your use of enumerate so I’ll answer the question as written.