如何计算莎士比亚戏剧中角色的行数[关闭]

问题描述 投票:0回答:0

我必须解决莎士比亚戏剧中每个角色所说的行数,给定一个 .txt 文件,结果是角色名称作为键,行数是值/行数。 .txt 文件包含整个剧本的文本,但角色名称仅在说话时全部大写。名称可以在同一行上加上引号,也可以单独使用。名称后面没有分号,也没有其他标记。我不知所措。

示例文本:

SAMPSON  Yes, better, sir.

ABRAM  You lie.

SAMPSON  Draw if you be men.--Gregory, remember
thy washing blow.   [They fight.]

BENVOLIO  Part, fools!  [Drawing his sword.]
Put up your swords. You know not what you do.

[Enter Tybalt, drawing his sword.]


TYBALT
What, art thou drawn among these heartless hinds?
Turn thee, Benvolio; look upon thy death.

BENVOLIO
I do but keep the peace. Put up thy sword,
Or manage it to part these men with me.

TYBALT
What, drawn and talk of peace? I hate the word
As I hate hell, all Montagues, and thee.
Have at thee, coward!   [They fight.]

[Enter three or four Citizens with clubs or partisans.]
python dictionary file text-files readlines
© www.soinside.com 2019 - 2024. All rights reserved.