For example given the following for loop:
for i in range(3):
print(i, '->',i+1)
Gives the output:
0 -> 1
1 -> 2
2 -> 3
How could I save this output in string form such that it is saved in a variable.
So for example could say print(my_variable) and the output is as the above output.
Edit Given the following list:
[['ORGANIZATION', 'EDUCATION', 'UniversityWon', 'FormMathematics'], ['PERSON', 'Sixth', 'Economics'], ['GPE', 'FrenchUK', 'London']]
I have the following for loop that prints them in the desired way:
for i in output:
print(i[0], '->', ', '.join(i[1:]))
Output of:
ORGANIZATION -> EDUCATION, UniversityWon, FormMathematics
PERSON -> Sixth, Economics
GPE -> FrenchUK, London
How can i save this output into a variable such that if i executed print(variable), the above output would be printed?
.format()method"\n".join(f'{i} -> {i + 1}' for i in range(3))