|
|
|
|
|
by keeperofdakeys
5332 days ago
|
|
x + [] or x[:] still has a readability issue, to anyone who hasn't done much python before, it isn't immediately obvious that you want to create a new list. For personal scripts, this may not matter too much, but for code that is seen by other people, you may be inhibiting their understanding. A good analogy is probably assuming that pointer sizes are the same as int sizes in C. This assumption was safe for many years, but broke when 64-bit came along. Slices and adding lists will probably always return new lists in python, but it is still good not to depend on such behaviour. |
|
Slices and adding lists will probably always return new lists in python, but it is still good not to depend on such behaviour.
Not buying this. The behavior is documented and Python has a deprecation cycle for changes in documented behavior.
The reason to write list(x) is because that's the generic way to turn anything into a list. It's not for being future proof or being easy for newbies to understand. It's because that's the right way to do it.