Is there any way to do this kind of string formatting using PYTHON3
*************Food*************
initial deposit 1000.00
groceries -10.15
restaurant and more foo -15.89
Transfer to Clothing -50.00
where the numbers are aligned to the right and the texts are aligned to the left
ledger = [
{'amount':10000,'description': 'initial deposit'},
{'amount':-10.15,'description': 'groceries'},
{'amount':-15.89,'description': 'restaurant and more food costings'},
{'amount':-50,'description': 'Transfer to Clothing'}
]
please note that the value of the description key might depending on the user... so It might be much longer or it might also not these ones
if I do
string = ''
for dic in ledger:
string += '{description:<23}{amount:>7.2f}'.format(**dic)
string += '\n'
print(string)
the output is like this...
initial deposit 10000.00
groceries -10.15
restaurant and more food costings -15.89
Transfer to Clothing -50.00
but I want the description part to stop before the numbers
also the decimal points are not aligning
so what else am I missing here Thank You!!!!