Is there a more elegant way to detect whether values in a list are negative, then positive?
For instance [-1, 0, -2, 2] returns True as -1 is negative and the index of 2 is higher than the index of -1.
[1, 2, 3, 2] returns False as all values are positive.
[-1, -2, -3, -4] returns False as all values are negative.
[4, 3, 2, 1, -1] returns False.
This is my code for this so far:
def my_function(my_list):
neg_index = None
for index, item in enumerate(my_list):
if item < 0:
neg_index = index
if item > 0:
pos_index = index
if neg_index is not None:
if pos_index > neg_index:
return True
return False