A program I'm using at work uses Python as a scripting language. I am perplexed in my attempts to modify a list while interating over it. Also, I have some logic inside the for loop that I would like to convert portions of the list from floats to text. In the end all the text have to be exactly 4 spaces. In my research to solve this problem I have come accross numerous simular problems for other people attempting to modify a list while iterating over it. However I feel my issue is unique because I am attempting to modify the list from floats to text while iterating over it.
I actually found a work around for the problem but I feel the solution was more complicated then it needed to be and I'm looking for a more simple solution which is the reason why I'm here. I would like to improve the code.
Here is the code which is giving me problems:
#these come in as floats with a single decimal space, ex:99.9
val = [AvailibilityLine1, AvailibilityLine2,
PerformanceLine1, PerformanceLine2,
QualityLine1, QualityLine2]
for i in val:
j = 0
if i >= 100:
val[j] = "100 "
elif i >= 10 and i < 100:
val[j] = str(val)
elif i > 0 and i < 10:
val[j] = " " + str(val)
elif i <= 0:
val[j] = " " #insert 4 spaces
else:
val[j] = " " #insert 4 spaces if all else fails
j=j+1