python找到一行单词中最长的_python - 查找.txt文件中最长的单词,不带标点符号 - SO中文参考 - www.soinside.com...

我正在做Python文件I / O练习,尽管在尝试查找.txt文件每一行中最长的单词的练习上取得了巨大进步,但我无法摆脱标点符号。] >

这是我的代码:with open("original-3.txt", 'r') as file1:

lines = file1.readlines()

for line in lines:

if not line == "\n":

print(max(line.split(), key=len))

这是我从中读取数据的原始-3.txt文件'Twas brillig, and the slithy toves

Did gyre and gimble in the wabe;

All mimsy were the borogoves,

And the mome raths outgrabe.

"Beware the Jabberwock, my son!

The jaws that bite, the claws that catch!

Beware the Jubjub bird, and shun

The frumious Bandersnatch!"

He took his vorpal sword in hand:

Long time the manxome foe he sought,

So rested he by the Tumtum tree,

And stood a while in thought.

And, as in uffish thought he stood,

The Jabberwock, with eyes of flame,

Came whiffling through the tulgey wood,

And burbled as it came!

One two! One two! And through and through

The vorpal blade went snicker-snack!

He left it dead, and with its head

He went galumphing back.

"And hast thou slain the Jabberwock?

Come to my arms, my beamish boy!"

"Oh frabjous day! Callooh! Callay!"

He chortled in his joy.

'Twas brillig, and the slithy toves

Did gyre and gimble in the wabe:

All mimsy were the borogoves,

And the mome raths outgrabe.

如您所见,我得到的标点符号是[“,”“;” “?” “!”]

您认为我自己只能说些什么?

谢谢

我正在做Python文件I / O练习,尽管在尝试查找.txt文件每一行中最长的单词的练习上取得了巨大的进步,但我无法摆脱标点符号。 ...

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值