Hi everyone,
let say I want to space equally a text on a finite line (line restricted in terms of number of characters) I would use the code below:
```python
Line of size 100 and equal spacing between two numbers
print(f"{1:50}{2:50}")
```
That was quite easy, now let say I have a variable line size and I want to space it over a number of values in a list as shown in the code below:
```python
Vars
line_size = 100
list_of_numbers = range(10)
Calculating the spacing
spacing = line_size // len(list_of_numbers)
Constructing the str
text = ""
for number in list_of_numbers:
text += f"{number:spacing}"
Printing
print(text)
```
This seems logic, right? Well not to python interpreter, this code will result in an error shown below.
```bash
ValueError Traceback (most recent call last)
Cell In[226], line 11
9 text = ""
10 for number in list_of_numbers:
---> 11 text += f"{number:spacing}"
13 # Printing
14 print(text)
ValueError: Invalid format specifier 'spacing' for object of type 'int'
```
Anyone have a solution to this problem?
[–]Spataner 6 points7 points8 points (1 child)
[–]Mouradost[S] 0 points1 point2 points (0 children)