Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert list of lists into a normal list

Tags:

python

list

I have a list of lists:

a = [['0.06'], ['0.54'], ['0.61']] 

I want to convert this list into normal list like this:

a = [0.06, 0.54, 0.61]

How can I do it it

like image 691
Anna Avatar asked Jan 26 '26 15:01

Anna


1 Answers

Using a list comprehension:

>>> a = [['0.06'], ['0.54'], ['0.61']]
>>> [float(x) for [x] in a]
[0.06, 0.54, 0.61]
like image 114
wim Avatar answered Jan 29 '26 04:01

wim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!