Friday, 27 September 2013

Python: Dividing integers in a list by another list UNTIL the result is zero

Python: Dividing integers in a list by another list UNTIL the result is zero

I have seen similar questions, but nothing to help me with this problem.
I have two lists, call them a and b. I want to take the first number in a,
and divide that by numbers in b. But upon reaching the first integer in b
where a % b == 0 (no remainder), I want the process to stop and then move
onto the next integer in a, and repeat the process. I can get the ultimate
result I need with a process that just divides each number in a by ALL
numbers in b and then gives the result, but that seems wasteful. The
operation should cut off as soon as a / (any b) gives a remainder of 0,
and then move onto the next a.
NB: I've tried using the any() function (e.g. a % any(b) == 0) but to no
avail.
Thanks for any help!

No comments:

Post a Comment