Search code examples
pythonpython-3.xfor-loopincrementsentence

How to add numbers i.e. increment before a sentence in python


How do i add numbers before the sentences in python. The code is given below

for output in outputs:
    line = tokenizer.decode(output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
    print(line)

And the output is :

I plan to visit Arsenal against Brighton match on April 9, and are you interested in meeting me at that match?
Hey, I'm planning to visit the game Arsenal vs Brighton on 9th April, are you interested with me in watching this game?

I'm trying to get the output like

1.) I plan to visit Arsenal against Brighton match on April 9, and are you interested in meeting me at that match?
2.) Hey, I'm planning to visit the game Arsenal vs Brighton on 9th April, are you interested with me in watching this game?

Can anyone help me with this?


Solution

  • You can use enumerate to increment automatically a counter and a f-string:

    outputs = ['line1', 'line2', 'line3']
    
    for n, output in enumerate(outputs):
        line = output.capitalize() # use your function here
        print(f'{n+1}.) {line}')
    

    output:

    1.) Line1
    2.) Line2
    3.) Line3