0 votes
1 view
in Python by (47.8k points)

I'm having a problem with square brackets in Python. I wrote a code that produces the following output:

[[180.0], [173.8], [164.2], [156.5], [147.2], [138.2]]

But I would like to perform some calculations with that, but the square brackets won't let me.

How can I remove the brackets? I saw some examples to do that but I could not apply them to this case.

1 Answer

0 votes
by (107k points)
edited by

For python flatten list you should use itertools.chain - this will also cater for > 1 element in each sublist:

from itertools import chain 

list(chain.from_iterable([[180.0], [173.8], [164.2], [156.5], [147.2], [138.2]]))

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...