Idiomatic backtracking in Python

sjmsoft at gmail.com sjmsoft at gmail.com
Tue Jan 27 07:48:47 EST 2015


On Sunday, January 25, 2015 at 4:15:58 PM UTC-4, Johannes Bauer wrote:
> Hi folks,
> 
> I have a problem at hand that needs code for backtracking as a solution.
> And I have no problem coding it, but I can't get rid of the feeling that
> I'm always solving backtracking problems in a non-Pythonic
> (non-idiomatic) way. So, I would like to ask if you have a Pythonic
> approach to backtracking problems? If so, I'd love to hear your solutions!

When I think of backtracking, I think of Prolog (to which backtracking is central).  You could use PySWIP to run SWI-Prolog from your Python program.  Not idiomatic Python backtracking, of course, but it would get the job done, and Prolog's backtracking is reliable and well-described.  It would help if you already know a bit of Prolog or are keen to learn.

Cheers,
  Steve J. Martin





More information about the Python-list mailing list