Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'detect': 0.07; 'override': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; 'thread': 0.14; 'container,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subclass': 0.16; 'threads,': 0.16; 'wrote:': 0.18; 'not,': 0.20; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'subject:like': 0.24; 'sort': 0.25; 'order.': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; "doesn't": 0.30; 'reaches': 0.30; 'container': 0.31; 'yields': 0.31; 'subject:with': 0.35; 'add': 0.35; 'there': 0.35; 'method': 0.36; 'similar': 0.36; 'should': 0.36; 'list': 0.37; 'implement': 0.38; 'checks': 0.38; 'to:addr :python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'length': 0.61; 'subject: ': 0.61; 'new': 0.61; 'numbers': 0.61; 'received:173': 0.61; 'such': 0.63; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: how to implement a queue-like container with sort function Date: Thu, 28 Nov 2013 21:31:36 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385692320 news.xs4all.nl 15907 [2001:888:2000:d::a6]:33900 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60754 On 11/28/2013 8:54 PM, iMath wrote: > I want to a fixed length list-like container, it should have a sorted()-like function that I can use to sort it,I think there should also a function I can use it to detect whether the numbers of items in it reaches the length of the container , because if the numbers of items in it reaches the length(fixed) of the container,I want to process the data in it .Is there a container in Python like this ?If not, what base container should be used to implement such container? > > the container is similar to queue ,but queue doesn't have a sort function For single thread use, subclass list, add a new .put method that checks the list size and either does self.append or self.sort(); process(list). For multiple threads, you need the queue module, which has extra features (and baggage). A PriorityQueue yields items in sorted order. Subclass it and override .put to either call the original .put or start a process thread. -- Terry Jan Reedy