Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Python: copying a list the right way

new = old[:]Those proficient in Python know what the previous line do. It copies the list old into new. This is confusing for beginners and should be avoided. Sadly the [:] notation is widely used, probably because most Python programmers don’t know a better way of copying lists.A little bit of pythonic theoryFirst we need to understand how Python manages objects & variables. Python doesn’t have variables like C. In C a variable is not just a name, it is a set of bits; a variable exists somewhere in memory. In Python variables are just tags ...

2,548 0       PYTHON LIST COPY REFERENCE [:] LIST()