0
print('The most frequent bigram tags are:\n')
bigram = bigram_frequency(lines)
for i in bigram:
    print(i[0]+"\t\t"+str(i[1]))

here's what I get:

N+N         5
N+DELM      3
DELM+DELM         2
N+P         2
DELM+P      2
P+N         2
DELM+N      2
CON+N       2
N+CON       2

How should I align that funny 2 from the third row with the rest of the group?

2 Answers 2

2

Youc can use format:

for i in [('fgd',1),('dg',2),('ggdd',3),( 'dd',4)]:
    print("{:5s} {:5d}".format(i[0], i[1]))


fgd       1
dg        2
ggdd      3
dd        4
Sign up to request clarification or add additional context in comments.

Comments

2

You can use string formatting to get a specific text width, padded with spaces:

for tag, frequency in bigram:
    print('{tag:10} {frequency}'.format(tag=tag, frequency=frequency))

Change the 10 to the maximum width of the first column.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.