You can try the built-in enumerate()
method:
lst = ['One', 'Two', 'Three']
for i, item in enumerate(lst, 1):
print(i, item)
Output:
1 One
2 Two
3 Three
A potential problem here is when the digits start becoming different lengths, like:
lst = ['One', 'Two', 'Three', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test']
Output:
1 One
2 Two
3 Three
4 test
5 test
6 test
7 test
8 test
9 test
10 test
11 test
12 test
13 test
where the starting point of each word doesn't align anymore. That can be fixed with the str.ljust()
method:
lst = ['One', 'Two', 'Three', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test']
for i, item in enumerate(lst, 1):
print(str(i).ljust(2), item)
Output:
1 One
2 Two
3 Three
4 test
5 test
6 test
7 test
8 test
9 test
10 test
11 test
12 test
13 test