Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19e7acf

Browse files
committed
Made doctests work in Python 2.4. Not sure it'll keep being worth it, but these changes were minor.
1 parent c9b0efa commit 19e7acf

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

csp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def support_pruning(self):
102102
"""Make sure we can prune values from domains. (We want to pay
103103
for this only if we use it.)"""
104104
if self.curr_domains is None:
105-
self.curr_domains = dict((v, self.domains[v][:]) for v in self.vars)
105+
self.curr_domains = dict((v, list(self.domains[v]))
106+
for v in self.vars)
106107

107108
def suppose(self, var, value):
108109
"Start accumulating inferences from assuming var=value."
@@ -498,7 +499,7 @@ def __init__(self, grid):
498499
the digits 1-9 denote a filled cell, '.' or '0' an empty one;
499500
other characters are ignored."""
500501
squares = iter(re.findall(r'\d|\.', grid))
501-
domains = dict((var, [int(ch)] if ch in '123456789' else range(1, 10))
502+
domains = dict((var, if_(ch in '123456789', [ch], '123456789'))
502503
for var, ch in zip(flatten(self.rows), squares))
503504
for _ in squares:
504505
raise ValueError("Not a Sudoku grid", grid) # Too many squares

logic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def is_definite_clause(s):
296296
elif s.op == '>>':
297297
antecedent, consequent = s.args
298298
return (is_symbol(consequent.op)
299-
and all(is_symbol(arg.op) for arg in conjuncts(antecedent)))
299+
and every(lambda arg: is_symbol(arg.op), conjuncts(antecedent)))
300300
else:
301301
return False
302302

@@ -828,8 +828,7 @@ def occur_check(var, x, s):
828828
return (occur_check(var, x.op, s) or
829829
occur_check(var, x.args, s))
830830
elif isinstance(x, (list, tuple)):
831-
return any(occur_check(var, element, s)
832-
for element in x)
831+
return some(lambda element: occur_check(var, element, s), x)
833832
else:
834833
return False
835834

probability.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def __init__(self, table):
174174
if isinstance(table, (float, int)): # no parents, 0-tuple
175175
self.table = {(): table}
176176
elif isinstance(table, dict):
177-
key = table.keys()[0] if table else None
177+
if table: key = table.keys()[0]
178+
else: key = None
178179
if isinstance(key, bool): # one parent, 1-tuple
179180
self.table = dict(((k,), v) for k, v in table.items())
180181
elif isinstance(key, tuple): # normal case, n-tuple

0 commit comments

Comments
 (0)