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

Skip to content

Removed unnecessary list coercions around map introduced by 2to3 usage #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def score(env):
env.add_thing(agent)
env.run(steps)
return agent.performance
return mean(list(map(score, envs)))
return mean(map(score, envs))

# _________________________________________________________________________

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def histogram(values, mode=0, bin_function=None):
Sorted by increasing value, or if mode=1, by decreasing count.
If bin_function is given, map it over values first."""
if bin_function:
values = list(map(bin_function, values))
values = map(bin_function, values)

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

sizes = list(
map(lambda seq: max(list(map(len, seq))),
list(zip(*[list(map(str, row)) for row in table]))))
map(lambda seq: max(map(len, seq)),
list(zip(*[map(str, row) for row in table]))))

for row in table:
print(sep.join(getattr(
Expand Down