I need to format an array into a string, however the string is prepared and stored before hand. Essentially I have a list of strings that look something like this:
text = [
'Data Item 1: %.2f',
'Data Item 2: %.2f',
'Data Item 3: %.2f'
]
This list is then looped through and data is assigned to it similar to this:
for i in range(len(text)):
print(text[i] % data[i])
This works fine but now I want to be able add a string to my text list which will later be paired with a list item like this:
text = [
'Data Item 1: %.2f',
'Data Item 2: %.2f',
'Data Item 3: %.2f',
'Num List: <FORMATTING NEEDED>'
]
data = [0.3, 2.1, 4.9, [1, 2, 3, 4]]
for i in range(len(text)):
print(text[i] % data[i])
I want this to bear the following result:
Data Item 1: 0.30
Data Item 2: 2.10
Data Item 3: 4.90
Num List: 1,2,3,4
The closest thing to what I'm looking for that I have found so far looks like this:
'Num List: ['+", ".join(['%.2f']*len(x))+"]'
But I don't have 'x' yet. I need to prepare the string for a list that isn't immediately usable. I hope I explained my need correctly.