I have a table where in one of the columns the data is a string that looks like this:
[{'label': 1, 'prob': 0.5001602182558444}, {'label': 0, 'prob': 0.49983978174415555}]
I want to extract just the number from label :1. So it would look like this:
0.5001602182558444
I can't seem to figure out how to do it with the standard methods since it has so many symbols which mess with the syntax.
You could use a generator with next:
next((x['prob'] for x in lst if x['label'] == 1), None)
0.5001602182558444
Notice I add a None in case for no matches, if you're sure there would be matches you can strip that None:
next((x['prob'] for x in lst if x['label'] == 1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With