使用 python 将文本文件中的所有单词组织到数组或链表中
我有一个以下格式的文本文件。
<InitialNode>-><MergeNode *merge>->("Prepare for election")
->["Equipment, voter lists, ballot styles and/or ballots"]-><ForkNode>
{ ->("Prepare for voting (precinct)")-><ForkNode>
{ ->("Gather in-person vote") // Includes early voting.
->["Ballots and/or ballot images"]->(Collect *c),
"Precinct count"->("Count (precinct count)")
->["Machine totals"]->0..1(*c)
}
我需要分割文本文件并以这样的方式存储元素,
array[0]=<InitialNode>
array[1]=->
array[2]=<MergeNode *merge>
array[3]=->
array[4]=("Prepare for election")
array[5]=->
array[6]=["Equipment, voter lists, ballot styles and/or ballots"]
array[7]=->
依此类推。
总之我需要在->的基础上分割整个文本。
'->' 之间的所有内容, ',' , '}' , '}' 必须存储在链表中或 大批。
我怎样才能使用 python 来做到这一点?
I have a text file of the following format.
<InitialNode>-><MergeNode *merge>->("Prepare for election")
->["Equipment, voter lists, ballot styles and/or ballots"]-><ForkNode>
{ ->("Prepare for voting (precinct)")-><ForkNode>
{ ->("Gather in-person vote") // Includes early voting.
->["Ballots and/or ballot images"]->(Collect *c),
"Precinct count"->("Count (precinct count)")
->["Machine totals"]->0..1(*c)
}
I need to split the text file and store the elements in such a way that
array[0]=<InitialNode>
array[1]=->
array[2]=<MergeNode *merge>
array[3]=->
array[4]=("Prepare for election")
array[5]=->
array[6]=["Equipment, voter lists, ballot styles and/or ballots"]
array[7]=->
and so on.
In short I need to split the entire text on the basis of ->.
All the things that comes between '->' , ',' , '}' , '}' must be stored in a linked list or
array.
How could I do this using python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你的初始字符串存储在 x.
要获取 x 中的所有文本,请这样做
这应该可以解决问题
If your initial string is stored in x.
To get all the text in x,do
This should do the trick
我只会使用字符串的内置
split
方法。但我不确定你所说的“'->'之间的所有事物”是什么意思, ',' , '}' , '}' 必须存储在链表或数组中。"这个有这个作用吗?或者您需要进一步拆分这些子字符串吗?
I would just use the built-in
split
method of strings.But I'm not sure what you mean by "All the things that comes between '->' , ',' , '}' , '}' must be stored in a linked list or array." Does this do that? Or do you need to split up these substrings further?