Removed unnecessary list coercions around map introduced by 2to3 usage by reachtarunhere · Pull Request #228 · aimacode/aima-python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agents.py
4 changes: 2 additions & 2 deletions csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def flatten(seqs): return sum(seqs, [])
_CELL = itertools.count().__next__
_BGRID = [[[[_CELL() for x in _R3] for y in _R3] for bx in _R3] for by in _R3]
_BOXES = flatten([list(map(flatten, brow)) for brow in _BGRID])
_ROWS = flatten([list(map(flatten, list(zip(*brow)))) for brow in _BGRID])
_ROWS = flatten([list(map(flatten, zip(*brow))) for brow in _BGRID])
_COLS = list(zip(*_ROWS))

_NEIGHBORS = {v: set() for v in flatten(_ROWS)}
Expand Down Expand Up @@ -583,7 +583,7 @@ def abut(lines1, lines2): return list(
map(' | '.join, list(zip(lines1, lines2))))
print('\n------+-------+------\n'.join(
'\n'.join(reduce(
abut, list(map(show_box, brow)))) for brow in self.bgrid))
abut, map(show_box, brow))) for brow in self.bgrid))
# ______________________________________________________________________________
# The Zebra Puzzle

Expand Down
4 changes: 2 additions & 2 deletions learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ def setproblem(self, target, inputs=None, exclude=()):
to not use in inputs. Attributes can be -n .. n, or an attrname.
Also computes the list of possible values, if that wasn't done yet."""
self.target = self.attrnum(target)
exclude = list(map(self.attrnum, exclude))
exclude = map(self.attrnum, exclude)
if inputs:
self.inputs = removeall(self.target, inputs)
else:
self.inputs = [a for a in self.attrs
if a != self.target and a not in exclude]
if not self.values:
self.values = list(map(unique, list(zip(*self.examples))))
self.values = list(map(unique, zip(*self.examples)))
self.check_me()

def check_me(self):
Expand Down
6 changes: 2 additions & 4 deletions logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def fetch_rules_for_goal(self, goal):


test_kb = FolKB(
list(map(expr, ['Farmer(Mac)',
map(expr, ['Farmer(Mac)',
'Rabbit(Pete)',
'Mother(MrsMac, Mac)',
'Mother(MrsRabbit, Pete)',
Expand All @@ -916,10 +916,9 @@ def fetch_rules_for_goal(self, goal):
# '(Human(h) & Mother(m, h)) ==> Human(m)'
'(Mother(m, h) & Human(h)) ==> Human(m)'
]))
)

crime_kb = FolKB(
list(map(expr,
map(expr,
['(American(x) & Weapon(y) & Sells(x, y, z) & Hostile(z)) ==> Criminal(x)', # noqa
'Owns(Nono, M1)',
'Missile(M1)',
Expand All @@ -929,7 +928,6 @@ def fetch_rules_for_goal(self, goal):
'American(West)',
'Enemy(Nono, America)'
]))
)


def fol_bc_ask(KB, query):
Expand Down
2 changes: 1 addition & 1 deletion search.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def genetic_algorithm(population, fitness_fn, ngen=1000, pmut=0.1):
for i in range(ngen):
new_population = []
for i in len(population):
fitnesses = list(map(fitness_fn, population))
fitnesses = map(fitness_fn, population)
p1, p2 = weighted_sample_with_replacement(population, fitnesses, 2)
child = p1.mate(p2)
if random.uniform(0, 1) < pmut:
Expand Down
6 changes: 3 additions & 3 deletions utils.py