1
Hello, I have a problem that I believe is relatively simple in python, but I can not solve it. I have a list of values that vary in positive and negative numbers. And I need to select from that list only the first positive value of when it rises from the negative. For example:
(id) - Valor
1 -1
2 -2
3 1
4 2
5 -2
6 -3
7 4
8 5
If the list of numbers were this I would need to select only the values that are in position(id) 3 and 7. The negative and positive values that are in the positions subsequent to the first ones do not serve. For negative values I solved the problem with the following line in the code:
for i in range(len(n)):
if n[i] > 0:
where i and n are lists I created.
If anyone has any tips, I’d appreciate it. Thank you.
How do id and value relate? If it were a simple list the indexes would start at 0.
– Woss
If it’s just a list you can use
zip()
, Slices and list comprehensions to achieve the expected result. See this example. Not put an answer because I do not know how is the data structure you are using.– fernandosavio