-1

I have a list and I'd like to print every item in that list along with other information in one line. Any advise will be appreciated.

l = ['absolute', 'nicest']
print 'P', l, 'Score'

The output will be:

P ['absolute', 'nicest'] Score

What I want to achieve is:

P absolute nicest Score

I know that I can use a for loop to print every item in the list but the problem is I'm writing it in a function, and I don't know where to add the for loop correctly, below is the original function, I'd like to only print every item in the tl list instead of the list entirely.

def sa_baseline(entry):
    pl = [] #Polarity sum list
    tl = [] #Term list
    for token in entry.split():
        if token in d:
            pl.append(d[token])
            tl.append(token)
            if sum(pl) == 0:
                print 'Neu'
            elif sum(pl) > 0:
                print 'P', tl, sum(pl)
            else:
                print 'N', tl, sum(pl)
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
LingxB
  • 497
  • 3
  • 7
  • 17

1 Answers1

1

you can do it in this way:

l = ['absolute', 'nicest']
print 'P', " ".join(l), 'Score'

convert the list into a space separated string

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125