I have a python dict like: {'prompt_0': {0: ' 0.75\n\nThis answer indicates a 75%…
- User
I have a python dict like:
{'prompt_0': {0: ' 0.75\n\nThis answer indicates a 75% probability that Ukraine will retake Polohy by October 1st, 2023.', 1: ' 0.75\n\nThis answer indicates a 75% probability that the EU Parliament will endorse a negotiating mandate for the AI Act before June 16, 2023.', 2: " 0.75\n\nThis forecast is based on the information provided in the question background, including President Zelenskyy's statement and the reports of preparations for the offensive being underway. It is also taking into account the fact that the question requires two of the four listed sources to report unequivocally that the counteroffensive has begun, which sets a relatively high bar for a positive resolution.\n\nGiven these factors, a probability estimate of 75% seems appropriate, indicating that there is a moderate to high likelihood that the question will resolve as true. However, it's important to note that there are many factors that could influence the outcome, and the forecast could change as new information becomes available.",
and so on
I want to extract the first number in each entry
Assistant
You can extract the first number from each entry in your dictionary using a list comprehension and the
split()method. Here's how you can do it:numbers = [int(key.split('_')[0]) for key in your_dict.keys()]This code creates a new list called
numbersthat contains the first number from each key in your dictionary. Thesplit()method is used to split each key into a list using the underscore character as the delimiter, and then the first element of that list (which is the number you're interested in) is extracted using indexing and converted to an integer using theint()function.You can then print out the numbers if you want to verify that they have been extracted correctly:
print(numbers)This should print out a list containing the first number from each key in your dictionary.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.