current position:Home>Use the virtual queue implemented by list to view the first element of the queue in Python without taking it out

Use the virtual queue implemented by list to view the first element of the queue in Python without taking it out

2022-04-29 19:31:37Wsyoneself

reason : because python Packaged Queue Of get Function to view the team leader, and the team leader element will be removed from the head remove, The time cost of restoring the original queue is high for operations that only view but do not fetch ( You need to take out the queues one by one and put them into )

solve : Use list Realization , The code is as follows

    def ackdata(num):
        index=0
        while True:
            tmp=self.seqs[index]
            if num>=tmp:
                index+=1
            else:
                break
            if index+1>len(self.seqs):
                self.seqs=[]
                break
        if index+1<len(self.seqs):
            self.seqs=self.seqs[index:] #  This enables virtual queues 

The team leader is greater than num Element pop-up , Stop when not more than .

copyright notice
author[Wsyoneself],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291742134219.html

Random recommended