A very basic question.. but I always do the bad implementation of this.
I have a list of ints.
And then I have a int “k” and “j”
I want to do something like this:
for ele in foo_list:
ele = (ele - k) / j
Is there a pythonic syntactic sugar to make this thing look pretty .
Also, i have a bad feeling like this is a very bad way and prone to bugs..
Is it safe to do an operation
val = function(val)
so you take an input and your output is saved to input.. Can this method become “Gotcha” at some point? or is it safe to do these kind of operations?
Thanks
Thanks.
Your code should be
Edit: To answer your second question,
val = f(val)is fine. But the way you were trying to use it doesn’t work:eleisn’t a pointer to the element in the list, it’s a variable name which happens to point to that element. When you assign something else to it, you’re making that variable name point somewhere else: you’re NOT writing into the location it points to.