'Python, How to find the min and max of a variable used in programme , without using if statment.?
Let's say 'price' variable is used to record stock price during the day. I need to know the min,max price during this period, without using comparison logic using if. Is there a function for that in Python? Thanks
Solution 1:[1]
This worked for me: Create empty List pr append new price every minute to list When done , find min,max of List
pr=[] 'create empty list pr.append(price) 'add price every minute or so min(pr),max(pr) 'get min,max of the list
This works, is there a shorter way? Better to use List or array? Thanks
Solution 2:[2]
min: numpy.org/doc/stable/reference/generated/numpy.ndarray.min.html
max: numpy.org/doc/stable/reference/generated/numpy.ndarray.max.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Misha Zabrodin |
| Solution 2 | Bruno Henrique Peixoto |
