You can use enumerate and string formatting to achieve this:
num_list = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
for _index, _value in enumerate(num_list):
if val <= 0:
_value = "" # If value is 0 or lower, just change it to empty string
elif val >= 100
_value = 100 # If value is greater than or equal to 100.0, make it 100
num_list[_index] = "{:>4}".format(_value)
>> num_list
>> [' 1.0', ' 2.0', ' 3.0', ' 4.0', ' 5.0', ' 6.0']
In format, "{:<4}"
defines the text formatting, <
means align text to left while, >
means align it right and ^
means center it. 4
defines the final length. It apply the preferred alignment and fill the rest with spaces. If you want to use a filling character instead of spaces, you can use it like
num_list[_index] = "{:*<4}".format(_value)
>> num_list
>> ['1.0*', '2.0*', '3.0*', '4.0*', '5.0*', '6.0*']
Where *
is your fill character