-1

Let's say I have the below list:

o =[[-0.90405713, -0.86583093, -0.14048125]]

How do I find out how positive each element of o[0] is?

So,by looking at this I know that -0.14048125 is the most "positive" with respect to 0 on the number line. Is there a way to do this via a python code?

user1452759
  • 8,810
  • 15
  • 42
  • 58

2 Answers2

3

If you want the value closest to 0, you could use min with abs as key:

>>> o =[-0.90405713,-0.86583093,-0.14048125,3]
>>> min(o, key=abs)
-0.14048125
Eric Duminil
  • 52,989
  • 9
  • 71
  • 124
0

use max()

>>> o =[-0.90405713,-0.86583093,-0.14048125]
>>> max(o)
-0.14048125
akash karothiya
  • 5,736
  • 1
  • 19
  • 29
  • Oh man! Thanks so much! It just didn't strike me to think of this. For some reason I was approaching this with respect to the number line and was thinking that I needed to do some mathematical calculations – user1452759 May 04 '17 at 13:57