2 ms·
This is interesting: > The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transpa
by dvfjsdhgfv 8y ago
This is interesting:
> The Python code snippet del a[i] deletes the element at index i from a list a. This code certainly is quite readable, but not so transparent: it’s easy to miss that the time complexity is O(n), where n is the number of elements in the list. Go doesn’t have a similar utility function. This is definitely less convenient, but also more transparent. Your code needs to explicitly state if it copies a section of the list. See 2 ways to delete an element from a slice[0] for a Go code example.
But the examples given in [0] could also be implemented in Python as well with, I dare say, the same time complexity.