Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: how to implement a queue-like container with sort function Date: Fri, 29 Nov 2013 17:53:11 +1300 Lines: 16 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ZomFYLq+ylxvF0GqOzrXpwny0MINPbmQgm+T7IcatJQBeaLKp6 Cancel-Lock: sha1:kxAXNsboat3Dc1rN2EGZrpm+NGo= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:60758 iMath wrote: > the container is similar to queue ,but queue doesn't have a sort function You can use a list as a queue. If you have a list l, then l.append(x) will add an item to the end, and l.pop(0) will remove the first item and return it. Then you just need to check the length of the list before adding an item, and if it's full, do something to process the items first. You can encapsulate all this inside a class if you want, but that's optional. -- Greg