Working of Cache-mem using Queue in Python
<p>I write a code to simulate the working of cache-memory. In this model, i try to realize the FIFO-algorhythm which allow to delete the last unused element (data, value, whatever). 
I wrote a special function, which give me a list <strong>o</strong> with numbers (these numbers are addresses in memory).</p>

<pre><code>q=Queue.Queue(800)# Cach - memory. This is queue which is more likely help me to simulate FIFO-algorhythm
QW=[] # External memory
l=raw_input("Enter a desire operation:")#I enter my operation.
for i in range(len(o)):
    time.sleep(0.4)
    u = time.time()
    k=o.pop(0) #o - is the list with numbers (these numbers are addresses in memory). Here is i get each address through pop.
    while l=='read': #If operation is "read" then i need to get my adress from q (cache-mem) or from QW (Is the external memory) and put it in q - (is the Cache-memory).
        if k not in q:
            if j in QW and k==j:
                q.put(j)
        else:
            q.get(k)
    while l=='record':#If operation is "record" then i need to write (append to QW) an address in QW or q, but only if the same address have existed already in QW or q.
        if k not in q:
            QW.append(k)
            print QW
        else:
            q.put(k)
    print q.get()
</code></pre>

<p>But i get the mistake: TypeError: argument of type 'instance' is not iterable at line</p>

<pre><code>if k not in q
</code></pre>

<p>Please help me to solve this problem!</p>

<p>You cant do that with Queues I think, instead use collections.dequeue which are almost similar while collections have fast append(), pop(). You can change your code first line to <code>q=collections.deque([],800)</code> and in place of q.put,q.get use <code>q.append</code> ,<code>q.popleft()</code>.</p>

python list caching queue