Python - counting sign changes
Posted
by dadashek
on Stack Overflow
See other posts from Stack Overflow
or by dadashek
Published on 2010-05-29T22:42:54Z
Indexed on
2010/05/29
22:52 UTC
Read the original article
Hit count: 273
I have a list of numbers I am reading left to right. Anytime I encounter a sign change when reading the sequence I want to count it.
X = [-3,2,7,-4,1,-1,1,6,-1,0,-2,1] X = [-, +, +, -, +, -, +, +, -, -,-,+]
So, in this list there are 8 sign changes.
When Item [0] (in this case -3) is negative it is considered a sign change. Also, any 0 in the list is considered [-].
Any help would be greatly appreciated.
© Stack Overflow or respective owner