I find it annoying that I can’t clear a list. In this example:
a = [] a.append(1) a.append(2) a = []
The second time I initialize a to a blank list, it creates a new instance of a list, which is in a different place in memory, so I can’t use it to reference the first, not to mention it’s inefficient.
The only way I can see of retaining the same pointer is doing something like the following:
for i in range(len(a)): a.pop()
This seems pretty long-winded though, is there a better way of solving this?
You are looking for: