Limit length of list python
<p>I don't know if this question was asked somewhere, but I did not find it.</p>

<p>I'm appending elements to a list. </p>

<pre><code>thr_core0 +=[fpid[thread]]
</code></pre>

<p>this happens periodically..
At time 0:</p>

<p>thr_core0 [9886, 9890]</p>

<p>At time1:</p>

<p>thr_core0 [9886, 9890, 9886, 9890]</p>

<p>Is it possible to limit the length of the list to 2. </p>

<p>I know it is possible using <code>deque</code>. but is it possible also using <code>lists</code>.</p>

<p>using <code>deque</code>, we do it like this:</p>

<pre><code>thr_core0 += [deque([0]*2,maxlen=2)]
</code></pre>

<p>These are the keywords I searched for on google: <code>limit</code> <code>list</code> <code>length</code> <code>python</code></p>
