How to remove all the elements in the array without changing its size in python
<p>If i created an array </p>

<pre><code>b = [[] for _ in xrange(10)]
</code></pre>

<p>and i store some numbers in it like this</p>

<pre><code>b = [[], [1], [22, 132], [3, 123], [], [], [6], [], [], [89]]
</code></pre>

<p>Now i want to delete all the elements and it should look like this</p>

<pre><code> b = [[], [], [], [], [], [], [], [], [], []]
</code></pre>

<p>but when i use this </p>

<pre><code> del b[:]
 print b
</code></pre>

<p>It becomes <code>b = []</code></p>

<p>I know <code>del b[:]</code> is applicable for list but what about array how to del elements from the array?</p>

<p>You need to loop over <code>b</code>, either setting each element to the empty list or deleting the contents of that element:</p>

<pre><code>for i in xrange(len(b)):
  b[i] = []
</code></pre>

<p>or</p>

<pre><code>for i in xrange(len(b)):
  del b[i][:]
</code></pre>

python