Here is an example:
x = ["changes": {"Average Response Time": ["22.93705940246582", "21.93705940246582"]}},]
How to extract only floats that I will recieve:
22.93705940246582
21.93705940246582
It is somehow "possible" but I will recommend you to start learning about Dictionnaries and Python data structure first.
Once you fixed your SyntaxError, assuming you have:
x = [{"changes": {"Average Response Time": ["22.93705940246582", "21.93705940246582"]}},]
You should be able to do:
print("\n\n".join(x[0]["changes"]["Average Response Time"]))
Full output:
>>> x = [{"changes": {"Average Response Time": ["22.93705940246582", "21.93705940246582"]}},]
>>> print("\n\n".join(x[0]["changes"]["Average Response Time"]))
22.93705940246582
21.93705940246582
>>>
About \n: It's the equivalent of "new line".
About x[0]["changes"]["Average Response Time"]: Your x variable is a list of dictionnaries.
To understand let's take it to step by step:
>>> x[0]
{'changes': {'Average Response Time': ['22.93705940246582',
'21.93705940246582']}}
>>>
"changes" key. That's what we do here.x[0]["changes"]
{'Average Response Time': ['22.93705940246582', '21.93705940246582']}
>>>
"Average Response Time" key. Same as before.>>> x[0]["changes"]["Average Response Time"]
['22.93705940246582', '21.93705940246582']
>>>
About str.join():
Return a string which is the concatenation of the strings in iterable. A TypeError will be raised if there are any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method.
I hope this helps, but please learn about Python lists, dictionaries, and data structure ASAP...
Your code is wrong since you used "changes": But write as a list, it should be a big dict outside. Your code should look like this:
You can do this:
x = {"changes": {"Average Response Time": ["22.93705940246582", "21.93705940246582"]}}
Then you can do:
print(x['changes']['Average Response Time'])
which gives you:
['22.93705940246582', '21.93705940246582']
If you want the first float:
print(x['changes']['Average Response Time'][0])
Otherwise, if you don't want a dict but want to make it a list. You can use this regular expression which will give you the numbers you want:
regex_digit_match = re.compile(r"(\d+(?:\.\d+)?)")
regex_digit_match.findall(yourlist[index])
x = [{"changes": {"Average Response Time": ["22.93705940246582", "21.93705940246582"]}},].xis not a valid python object.