Is there any way to pass a pointer to a list, so I could have
update_list(list, data)
Instead of having to do
list = update_list(list, data)
Independent of whether this is possible, what is advisable and Pythonic in this situation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I recommend reading Semantics of Python variable names from a C++ perspective:
This is oversimplification of the entire article, but this (and the understanding that a
listis a mutable type) should help you understand how the following example works.You can even shorten this by using the extend() method:
Which actually probably removes the need of your function.
N.B:
listis a built-in and therefore a bad choice for a variable name.