Skip to content

Commit ec683e2

Browse files
authored
Merge pull request #13 from gogasca/patch-1
Replace map and lambdas with list comprehensions in test file
2 parents bc2cc37 + 90bb0a0 commit ec683e2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
word_dict, reversed_dict, article_max_len, summary_max_len = build_dict("valid", args.toy)
1212
print("Loading validation dataset...")
1313
valid_x = build_dataset("valid", word_dict, article_max_len, summary_max_len, args.toy)
14-
valid_x_len = list(map(lambda x: len([y for y in x if y != 0]), valid_x))
14+
valid_x_len = [len([y for y in x if y != 0]) for x in valid_x]
1515

1616
with tf.Session() as sess:
1717
print("Loading saved model...")
@@ -24,7 +24,7 @@
2424

2525
print("Writing summaries to 'result.txt'...")
2626
for batch_x, _ in batches:
27-
batch_x_len = list(map(lambda x: len([y for y in x if y != 0]), batch_x))
27+
batch_x_len = [len([y for y in x if y != 0]) for x in batch_x]
2828

2929
valid_feed_dict = {
3030
model.batch_size: len(batch_x),
@@ -33,7 +33,7 @@
3333
}
3434

3535
prediction = sess.run(model.prediction, feed_dict=valid_feed_dict)
36-
prediction_output = list(map(lambda x: [reversed_dict[y] for y in x], prediction[:, 0, :]))
36+
prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
3737

3838
with open("result.txt", "a") as f:
3939
for line in prediction_output:

0 commit comments

Comments
 (0)