Given a list of floats
spendList, I want to apply round()
to each item, and either update the list in place with the rounded values, or create a new list.
I'm imagining this employing list comprehension to create the new list (if the original can't be overwritten), but what about the passing of each item to the round()
?
I discovered sequence unpacking here so tried:
round(*spendList,2)
and got:
TypeError Traceback (most recent call last)
<ipython-input-289-503a7651d08c> in <module>()
----> 1 round(*spendList)
TypeError: round() takes at most 2 arguments (56 given)
So surmising that round
was trying to round each item in the list, I tried:
[i for i in round(*spendList[i],2)]
and got:
In [293]: [i for i in round(*spendList[i],2)]
File "<ipython-input-293-956fc86bcec0>", line 1
[i for i in round(*spendList[i],2)]
SyntaxError: only named arguments may follow *expression
Can sequence unpacking even be used here? If not, how can this be achieved?