I've got a string which I want to format() with elements of an array (incrementally). Right now, the elements are placed via .format(*arr) but I want to run formatNumbers() for each element first and have its output placed in the string.
def formatNumbers(number):
return str("{:,}".format(number)).replace(",", " ")
def displayNumbers():
arr = [ 1000, 2000, 3000, 4000, 5000 ]
myString = "Numbers:\n{}\n{}\n{}\n{}\n{}".format(*arr)
print(myString)
Is there a fast way of doing this? Just writing .format(formatNumbers(*arr)) doesn't seem to work.
Do I need to make a "temporary array" to store the strings an then use the * operator to iterate through them, or is there an easier way?
Current output:
Numbers:
1000
2000
3000
4000
5000
Desired output (via calling formatNumbers()):
Numbers:
1 000
2 000
3 000
4 000
5 000