在python中将Doc对象转换为字符串
我正在使用 minidom 来解析 xml 文档。我用 yum 标签获取数据并将它们存储在列表中并计算单词的频率。但是,它不会将它们作为字符串存储或读取在列表中。还有其他方法吗?现在这就是我所拥有的:
yumNodes = [node for node in doc.getElementsByTagName("yum")]
for node in yumNodes:
yumlist.append(t.data for t in node.childNodes if t.nodeType == t.TEXT_NODE)
for ob in yumlist:
for o in ob:
if word not in freqDict:
freqDict[word] = 1
else:
freqDict[word] += 1
I'm using minidom to parse through an xml document. I took the data with yum tags and stored them in a list and calculated the frequency of the words. However, its not storing or reading them as strings in the list. Is there another way to do it? Right now this is what I have:
yumNodes = [node for node in doc.getElementsByTagName("yum")]
for node in yumNodes:
yumlist.append(t.data for t in node.childNodes if t.nodeType == t.TEXT_NODE)
for ob in yumlist:
for o in ob:
if word not in freqDict:
freqDict[word] = 1
else:
freqDict[word] += 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与您的问题没有直接关系,但作为可以改进您的代码的评论...该模式
通常被替换为
或 2.5 之前的版本
Not directly related to your question, but as a remark that could improve your code...the pattern
is usually replaced with
or pre-2.5
替换
为以下内容:
Replace
with the following: