By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

How to create an algorithm to evaluate a string?

P: 27
Hello All!
I am using mysql and python together. I have a table with only two columns: Number and Price. It looks something like this:
Number, Price
1, 10
2, 13
3, 19
4, 12
etc.

This continues for 90 rows until the Number values restart at 1, however the Price values keep changing. In all there are 900 rows.
What I would like to do is take the Price at all Number 2 and subtract that from the Price at Number 5. Then take the Price at Number 4 and subtract that from the Price at Number 5. If both of these numbers are positive or both are negative, I would like to store that number and move onto the next set of 90 Numbers. If They are both not positive or both not negative, then I would like to move on to the Price at number 5 subtract that from the Price at Number 6, Now check if this number has the same sign as the difference between Number 2 and Number 6.
So in all there should be a string of 10 values, one from each set of 90 numbers.
Any help at all will be greatly appreciated!
Thank you,
Ron Parker
Jan 11 '11 #1
Share this Question
Share on Google+
1 Reply


P: 27
Sorry, I did not include a starting point. Also, I apologize if my values look a little funny. However, I thought something like this to begin. As you can see, I am not very good at this though. So again, help me please!
Ron Parker

Expand|Select|Wrap|Line Numbers
  1. >>> Price = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  2. >>> def Best(seq):
  3. ...     first seq(5)-seq(2)
  4.         second seq(5)-seq(4)
  5.         if first/numpy.abs(first)=second/numpy.abs(second)
  6.               return second
  7.         else
  8.             seq(5+1)-seq(2+1)
  9.  
  10. ... 
  11. >>> [best(data[i:i+90]) for i in range(0, len(data), 90)]
  12.  
  13.  
  14.  
  15.  
Jan 11 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.