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

Skip to content

Commit 4138da5

Browse files
committed
In print_table() don't print trailing whitespace.
1 parent 97abf67 commit 4138da5

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

mdp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ def policy_evaluation(pi, U, mdp, k=20):
149149
[['>', '>', '>', '.'], ['^', None, '^', '.'], ['^', '>', '^', '<']]
150150
151151
>>> print_table(Fig[17,1].to_arrows(pi))
152-
> > > .
153-
^ None ^ .
154-
^ > ^ <
152+
> > > .
153+
^ None ^ .
154+
^ > ^ <
155155
156156
>>> print_table(Fig[17,1].to_arrows(policy_iteration(Fig[17,1])))
157-
> > > .
158-
^ None ^ .
159-
^ > ^ <
157+
> > > .
158+
^ None ^ .
159+
^ > ^ <
160160
"""
161161

162162
__doc__ += random_tests("""

search.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,14 @@ def do(searcher, problem):
789789
def compare_graph_searchers():
790790
"""Prints a table of results like this:
791791
>>> compare_graph_searchers()
792-
Searcher Romania(A, B) Romania(O, N) Australia
793-
breadth_first_tree_search < 21/ 22/ 59/B> <1158/1159/3288/N> < 7/ 8/ 22/WA>
794-
breadth_first_graph_search < 11/ 12/ 28/B> < 33/ 34/ 76/N> < 6/ 7/ 19/WA>
795-
depth_first_graph_search < 9/ 10/ 23/B> < 16/ 17/ 39/N> < 4/ 5/ 13/WA>
796-
iterative_deepening_search < 11/ 33/ 31/B> < 656/1815/1812/N> < 3/ 11/ 11/WA>
797-
depth_limited_search < 54/ 65/ 185/B> < 387/1012/1125/N> < 50/ 54/ 200/WA>
798-
astar_search < 3/ 4/ 9/B> < 8/ 9/ 22/N> < 2/ 3/ 6/WA>
799-
recursive_best_first_search < 200/ 201/ 601/B> < 71/ 72/ 213/N> < 11/ 12/ 43/WA> """
792+
Searcher Romania(A, B) Romania(O, N) Australia
793+
breadth_first_tree_search < 21/ 22/ 59/B> <1158/1159/3288/N> < 7/ 8/ 22/WA>
794+
breadth_first_graph_search < 11/ 12/ 28/B> < 33/ 34/ 76/N> < 6/ 7/ 19/WA>
795+
depth_first_graph_search < 9/ 10/ 23/B> < 16/ 17/ 39/N> < 4/ 5/ 13/WA>
796+
iterative_deepening_search < 11/ 33/ 31/B> < 656/1815/1812/N> < 3/ 11/ 11/WA>
797+
depth_limited_search < 54/ 65/ 185/B> < 387/1012/1125/N> < 50/ 54/ 200/WA>
798+
astar_search < 3/ 4/ 9/B> < 8/ 9/ 22/N> < 2/ 3/ 6/WA>
799+
recursive_best_first_search < 200/ 201/ 601/B> < 71/ 72/ 213/N> < 11/ 12/ 43/WA>"""
800800
compare_searchers(problems=[GraphProblem('A', 'B', romania),
801801
GraphProblem('O', 'N', romania),
802802
GraphProblem('Q', 'WA', australia)],

utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def issequence(x):
627627
"Is x a sequence? We say it is if it has a __getitem__ method."
628628
return hasattr(x, '__getitem__')
629629

630-
def print_table(table, header=None, sep=' ', numfmt='%g'):
630+
def print_table(table, header=None, sep=' ', numfmt='%g'):
631631
"""Print a list of lists as a table, so that columns line up nicely.
632632
header, if specified, will be printed as the first row.
633633
numfmt is the format for all numbers; you might want e.g. '%6.2f'.
@@ -641,9 +641,8 @@ def print_table(table, header=None, sep=' ', numfmt='%g'):
641641
maxlen = lambda seq: max(map(len, seq))
642642
sizes = map(maxlen, zip(*[map(str, row) for row in table]))
643643
for row in table:
644-
for (j, size, x) in zip(justs, sizes, row):
645-
print getattr(str(x), j)(size) + sep,
646-
print
644+
print sep.join(getattr(str(x), j)(size)
645+
for (j, size, x) in zip(justs, sizes, row))
647646

648647
def AIMAFile(components, mode='r'):
649648
"Open a file based at the AIMA root directory."

0 commit comments

Comments
 (0)