You can evaluate the length in digits of the longest entry by evaluating the length of its length. For example, 99 is 2 digits long, and len(str(99))
is 2, meaning two characters are needed.
We can then take advantage of f-string formatting to produce the following result:
for x in range(len(rankings)):
print(f'{x+1:0{len(str(len(rankings)))}}. xxx')
Example:
rankings = [1]*5
for x in range(len(rankings)):
print(f'{x+1:0{len(str(len(rankings)))}}. xxx')
produces this result:
1. xxx
2. xxx
3. xxx
4. xxx
5. xxx
>>>
while
rankings = [1]*50
for x in range(len(rankings)):
print(f'{x+1:0{len(str(len(rankings)))}}. xxx')
produces this result:
01. xxx
02. xxx
03. xxx
04. xxx
05. xxx
06. xxx
07. xxx
08. xxx
09. xxx
10. xxx
11. xxx
12. xxx
13. xxx
14. xxx
15. xxx
16. xxx
17. xxx
18. xxx
19. xxx
20. xxx
21. xxx
22. xxx
23. xxx
24. xxx
25. xxx
26. xxx
27. xxx
28. xxx
29. xxx
30. xxx
31. xxx
32. xxx
33. xxx
34. xxx
35. xxx
36. xxx
37. xxx
38. xxx
39. xxx
40. xxx
41. xxx
42. xxx
43. xxx
44. xxx
45. xxx
46. xxx
47. xxx
48. xxx
49. xxx
50. xxx
>>>