4 ms·
I also like list(s) for its clarity and universality (the same technique works with dict(m) and deque(d) for example). The s[:] gets called faster (builtin syn
by raymondh 15y ago
I also like list(s) for its clarity and universality (the same technique works with dict(m) and deque(d) for example).
The s[:] gets called faster (builtin syntax dispatches directly) than list(s) which requires a global lookup. One called though, they both run the same underlying code and are therefore equally fast when it comes to the actual copying.
In Python 3.3, we're adding list.copy() and list.clear() because so many people were having issues with the [:] notation for copying and clearing.