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

Skip to content

Commit 6525e23

Browse files
reachtarunherenorvig
authored andcommitted
Removed unnecessary list coercions around map (aimacode#228)
1 parent 194a2f1 commit 6525e23

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ def score(env):
848848
env.add_thing(agent)
849849
env.run(steps)
850850
return agent.performance
851-
return mean(list(map(score, envs)))
851+
return mean(map(score, envs))
852852

853853
# _________________________________________________________________________
854854

csp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def flatten(seqs): return sum(seqs, [])
510510
_CELL = itertools.count().__next__
511511
_BGRID = [[[[_CELL() for x in _R3] for y in _R3] for bx in _R3] for by in _R3]
512512
_BOXES = flatten([list(map(flatten, brow)) for brow in _BGRID])
513-
_ROWS = flatten([list(map(flatten, list(zip(*brow)))) for brow in _BGRID])
513+
_ROWS = flatten([list(map(flatten, zip(*brow))) for brow in _BGRID])
514514
_COLS = list(zip(*_ROWS))
515515

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

learning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ def setproblem(self, target, inputs=None, exclude=()):
101101
to not use in inputs. Attributes can be -n .. n, or an attrname.
102102
Also computes the list of possible values, if that wasn't done yet."""
103103
self.target = self.attrnum(target)
104-
exclude = list(map(self.attrnum, exclude))
104+
exclude = map(self.attrnum, exclude)
105105
if inputs:
106106
self.inputs = removeall(self.target, inputs)
107107
else:
108108
self.inputs = [a for a in self.attrs
109109
if a != self.target and a not in exclude]
110110
if not self.values:
111-
self.values = list(map(unique, list(zip(*self.examples))))
111+
self.values = list(map(unique, zip(*self.examples)))
112112
self.check_me()
113113

114114
def check_me(self):

logic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ def fetch_rules_for_goal(self, goal):
903903

904904

905905
test_kb = FolKB(
906-
list(map(expr, ['Farmer(Mac)',
906+
map(expr, ['Farmer(Mac)',
907907
'Rabbit(Pete)',
908908
'Mother(MrsMac, Mac)',
909909
'Mother(MrsRabbit, Pete)',
@@ -916,10 +916,9 @@ def fetch_rules_for_goal(self, goal):
916916
# '(Human(h) & Mother(m, h)) ==> Human(m)'
917917
'(Mother(m, h) & Human(h)) ==> Human(m)'
918918
]))
919-
)
920919

921920
crime_kb = FolKB(
922-
list(map(expr,
921+
map(expr,
923922
['(American(x) & Weapon(y) & Sells(x, y, z) & Hostile(z)) ==> Criminal(x)', # noqa
924923
'Owns(Nono, M1)',
925924
'Missile(M1)',
@@ -929,7 +928,6 @@ def fetch_rules_for_goal(self, goal):
929928
'American(West)',
930929
'Enemy(Nono, America)'
931930
]))
932-
)
933931

934932

935933
def fol_bc_ask(KB, query):

search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def genetic_algorithm(population, fitness_fn, ngen=1000, pmut=0.1):
584584
for i in range(ngen):
585585
new_population = []
586586
for i in len(population):
587-
fitnesses = list(map(fitness_fn, population))
587+
fitnesses = map(fitness_fn, population)
588588
p1, p2 = weighted_sample_with_replacement(population, fitnesses, 2)
589589
child = p1.mate(p2)
590590
if random.uniform(0, 1) < pmut:

utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def histogram(values, mode=0, bin_function=None):
8686
Sorted by increasing value, or if mode=1, by decreasing count.
8787
If bin_function is given, map it over values first."""
8888
if bin_function:
89-
values = list(map(bin_function, values))
89+
values = map(bin_function, values)
9090

9191
bins = {}
9292
for val in values:
@@ -299,8 +299,8 @@ def print_table(table, header=None, sep=' ', numfmt='%g'):
299299
for row in table]
300300

301301
sizes = list(
302-
map(lambda seq: max(list(map(len, seq))),
303-
list(zip(*[list(map(str, row)) for row in table]))))
302+
map(lambda seq: max(map(len, seq)),
303+
list(zip(*[map(str, row) for row in table]))))
304304

305305
for row in table:
306306
print(sep.join(getattr(

0 commit comments

Comments
 (0)