How do i reduce this to a single function - the code is largely similar, just a direction of search toggle.

Denis McMahon denismfmcmahon at
Fri Nov 7 16:18:35 CET 2014

On Fri, 07 Nov 2014 16:46:19 +0630, Veek M wrote:

(1) Pass a true or false parameter to the function as the direction of 
search toggle.

(2) replace the relevant assignments with something like:

variable = something if condition else something else

(3) Figuring out the while loop control is a bit trickier, the best I 
came up with was:

while direction and condition_a or (not direction) and condition_b

But I'm sure someone has something better

Denis McMahon, denismfmcmahon at

More information about the Python-list mailing list