Factor every element of list in python, then append factors to sub-arrays in another array -


Here's my target factor every single element in the first and second positions, all the factors Adding to Public Man and PQN 3, which will then be linked to the main lists pqnum2 (for the first factor) and pqnum4 (for the secured factors) In addition, the first and secondary can be added by the user ( Has not been shown). Below is the code:

  define suggested lists pqnum = [] pqnum2 = [] pqnum3 = [] pqnum4 = [] # when loop counters are fib = 1 sib = 1 # listings findings Remove (user can be added) first = = 24, -1, 1, 0, -800, 2, 6] seconds = [2, -1, 1, 1, 30, 11, 5] # The first category for the factor index (0, lane (first) -1): x = first [index] while fib & lt; = X: if x% fib == 0: pqnum.append (fib) pqnum.append (-fib) fib = fib + 1 pqnum2.append (pqnum) print pqnum2 #factor indexed in index range (0, lane (secondary) -1): While sib & lt; = Secured [index]: if the second option [index]% sib == 0: pqnum3.append (sib) pqnum3.append (-sib) sib = sib + 1 pqnum4.append (pqnum3) print pqnum4   

Expected output is:

  [[1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8 , [1, -1, 2, - 12, -12, 24, -24], [1, -1], [1, -1], [0], [all factors -800, positive or negative] 2], [1, -1], [1, -1], [1, - 1], [1, -1, 2, -2, 3, -3]] [1, -1, 2, -2] 1], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1] , 11, -11], [1, -1,5, -5]]   

But the output that comes out of the code:

  [ [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [1, - 1, 2, -2, 3, -3, 4, -4, 6, -6, 8 , -8, 12, -12, 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12 , 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [ 1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24]] [[1, -1, 2, -2, -3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, - 6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15 , -1, 15, 30, -30 ], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30]]   

I was thinking about it for days I can not know why, please

you do not reset any of your variables O

When you code your <> Febe & lt; = X: For the first time the loop crosses, after the fib = 24 and pqnum = [1, -1], 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24] . When you reach that loop a second time, those values ​​do not change, so compare phab fails immediately, because 24 < -1 is false, and the same array is added to pqnum in pqnum2 .

Once you fix this, you will see that the list of factors of your -1 will be empty, because the comparison fib < = X still 1 & lt; Based on your logic, I will use a full value for x populating this clue:

  #factor The first category In index (0, lane (first) -1): x = ABS (first [index]) fib = 1 pqnum = [] while Fib & Lt; = X: if x% fib == 0: pqnum.append (fib) pqnum.append (-fib) fib = fib + 1 pqnum2.append (pqnum) print pqnum2    < / Html>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -