Parsing/Printing 取决于 Python 中的字符长度; CodeEval 只有 98%
Parsing/Printing depending on char length in Python; only 98% on CodeEval
所以我现在正在解决一个 CodeEval 问题,并且由于某种原因,我无法超过 98/100 分。
这是 CodeEval 上的 link 挑战:
https://www.codeeval.com/open_challenges/167/
这是我的代码:
# -*- coding: utf-8 -*-
import sys
zeefile = open(sys.argv[1])
for line in zeefile:
if len(line) <= 55:
sys.stdout.write(line)
elif len(line) > 55:
line = line[:40].rsplit(" ", 1)[0]
sys.stdout.write(line)
sys.stdout.write('... <Read More> \n')
我已经用头撞墙几个小时了,即使有一些开发人员比我更有才华。
至少可以说,我们很困惑。归根结底,这没什么大不了的,但我想知道这里是否遗漏了什么,以便我可以从中学习。
我一遍又一遍地检查了代码,我检查了输入,我检查了输出...我找不到任何不一致之处,或者任何表明我遗漏了最后 2 个的东西成功解决方案的百分比。
知道我们遗漏了什么,为什么这不能作为问题的 100% 合法解决方案回来吗?我希望一些新鲜的眼睛和敏锐的头脑可以帮助我解决这个问题!非常感谢!
尝试以下代码(代码评估 100%):
import sys
with open(sys.argv[1], 'r') as in_f:
for line in in_f:
line = line.strip()
if len(line) > 55:
line = "{0}... <Read More>".format(line[:40].rsplit(" ", 1)[0].rstrip())
sys.stdout.write("{0}\n".format(line))
我使用了这个文件:
Tom exhibited.
Amy Lawrence was proud and glad, and she tried to make Tom see it in her face - but he wouldn't look.
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many - very, very great many.
Tom's mouth watered for the apple, but he stuck to his work.
并得到以下输出:
Tom exhibited.
Amy Lawrence was proud and glad, and... <Read More>
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many -... <Read More>
Tom's mouth watered for the apple, but... <Read More>
所以我现在正在解决一个 CodeEval 问题,并且由于某种原因,我无法超过 98/100 分。
这是 CodeEval 上的 link 挑战:
https://www.codeeval.com/open_challenges/167/
这是我的代码:
# -*- coding: utf-8 -*-
import sys
zeefile = open(sys.argv[1])
for line in zeefile:
if len(line) <= 55:
sys.stdout.write(line)
elif len(line) > 55:
line = line[:40].rsplit(" ", 1)[0]
sys.stdout.write(line)
sys.stdout.write('... <Read More> \n')
我已经用头撞墙几个小时了,即使有一些开发人员比我更有才华。
至少可以说,我们很困惑。归根结底,这没什么大不了的,但我想知道这里是否遗漏了什么,以便我可以从中学习。
我一遍又一遍地检查了代码,我检查了输入,我检查了输出...我找不到任何不一致之处,或者任何表明我遗漏了最后 2 个的东西成功解决方案的百分比。
知道我们遗漏了什么,为什么这不能作为问题的 100% 合法解决方案回来吗?我希望一些新鲜的眼睛和敏锐的头脑可以帮助我解决这个问题!非常感谢!
尝试以下代码(代码评估 100%):
import sys
with open(sys.argv[1], 'r') as in_f:
for line in in_f:
line = line.strip()
if len(line) > 55:
line = "{0}... <Read More>".format(line[:40].rsplit(" ", 1)[0].rstrip())
sys.stdout.write("{0}\n".format(line))
我使用了这个文件:
Tom exhibited.
Amy Lawrence was proud and glad, and she tried to make Tom see it in her face - but he wouldn't look.
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many - very, very great many.
Tom's mouth watered for the apple, but he stuck to his work.
并得到以下输出:
Tom exhibited.
Amy Lawrence was proud and glad, and... <Read More>
Tom was tugging at a button-hole and looking sheepish.
Two thousand verses is a great many -... <Read More>
Tom's mouth watered for the apple, but... <Read More>