Reputation: 3241
I have:
a=[[1,2,3],[2,3,4],[3,4,5]]
I want to reuse a
and empty it. Is it correct to do a=list()
or I need to go manually into each list and empty it?
Upvotes: 2
Views: 43
Reputation: 13789
a = list()
or a = []
will create a new list object. If you actually want to empty the list, a[:] = []
or del a[:]
will do that. If you print id(a)
before and after each operation you'll see the difference.
There's no need to empty out the sublists. If there are no references remaining they'll be garbage collected.
Upvotes: 3