如何在每次迭代中打印出名称/标签

时间:2018-05-08 21:29:31

标签: python

我有一个函数可以打印出pos / neg / neu文本的分数。

所以我的输出如下:

# of sentences: 100
Pos Tally: 25
Neg Tally: 50
Neu Tally: 25

但是我没有为每个文本执行此操作,而是将文本放入列表中:

a = "How are you?"
b = "I am doing great."
c = "I am not doing well."

topics = [a,b,c]

我的功能是打印出' a',''' c'在给出计数之前,我假设我应该将标签放入列表中。

labels = ['a','b','c']

所以,我尝试了以下几点:

for i in topics:
    for label in labels:
        print(label, getSent(i))

这只是在每次pos / neg / neu计数后打印出整个标签。

我希望我的输出看起来像:

a
# of sentences: 1
Pos count: 1

b
# of sentences: 1

我可以做些什么来完成这项工作?

感谢。

1 个答案:

答案 0 :(得分:0)

您应该能够使用zip并排迭代标签和主题,这是一个示例(仅使用随机get_sent函数):

def get_sent(topic):
  return '\nPositive: 1\n'

for i, j in zip(topics, labels):
  print(j, get_sent(i))

输出:

a 
Positive: 1

b 
Positive: 1

c 
Positive: 1