I wish to make a function whose arguments are the name of a list L, and its arguments. The list L has just numbers in it, and I want to round them all to 1 decimal(by the way, the elements of the list L should be replaced by the rounded numbers, I don't want a new list M with them). Sadly, the list name varies in the script I'm planning, and so does the length of such lists. Here is my failed attempt:
def rounding(name,*args):
M=[round(i,1) for i in args] #here is the list I want L to become
name=M #here I try to replace the previous list with the new one
morada=[1,2.2342,4.32423,6.1231] #an easy example
rounding(morada,*morada)
print morada
Output:
[1, 2.2342, 4.32423, 6.1231] #No changes
Have the
rounding
functionreturn
a value.Then you can do this:
Or if you really really wanted it to assign within the function you could do this: