Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'def': 0.12; 'stored': 0.12; 'buffer,': 0.16; 'container,': 0.16; 'etc...': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'item):': 0.16; 'labelled': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'self.buffer': 0.16; 'simpson': 0.16; 'storing': 0.16; 'size,': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User- Agent:1': 0.23; 'subject:like': 0.24; 'cheers,': 0.24; 'sort': 0.25; 'purposes': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:( 50': 0.31; 'class': 0.32; 'totally': 0.33; 'sense': 0.34; 'skip:_ 10': 0.34; 'subject:with': 0.35; 'something': 0.35; 'there': 0.35; 'doubt': 0.36; 'received:com.au': 0.36; 'charset :us-ascii': 0.36; 'received:211': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'subject: ': 0.61; 'first': 0.61; 'content-disposition:inline': 0.62; 'worth': 0.66; 'bottom': 0.67; 'nuclear': 0.84; 'top.': 0.84; 'british': 0.87 Date: Fri, 29 Nov 2013 17:19:25 +1100 From: Cameron Simpson To: python-list@python.org Subject: Re: how to implement a queue-like container with sort function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=bpB1Wiqi c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=SrBxplfS2hYA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=8AHkEIZyAAAA:8 a=i8wGUEO_q4UA:10 a=Byx-y9mGAAAA:8 a=xj9RWx1Z_tWWWC70QR8A:9 a=CjuIK1q_8ugA:10 a=lSQsbIguPOwA:10 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385705979 news.xs4all.nl 15983 [2001:888:2000:d::a6]:36593 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60759 On 28Nov2013 18:04, iMath wrote: > All in all,I want to first fill the container, then sort it and process all the contents in it Automatically? It sounds like an I/O buffer, in the sense that a block buffered output stream does a write on buffer full. Something like this: class Chunkifier: def __init__(self, size, process): self.size = size self.buffer = [] def append(self, item): self.buffer.append(item) if len(self.buffer) >= self.size: process(sorted(self.buffer)) self.buffer = [] def extend(self, items): for item in items: self.append(item) def burp(items): for item in items: print item burper = Chunkifier(10, burp) burper.extend( (9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1) ) Totally untested, buyer beware, worth what you paid for it, etc... Cheers, -- Cameron Simpson It is necessary for technical reasons that these warheads be stored with the top at the bottom and the bottom at the top. In order that there may be no doubt as to which is the top and which is the bottom, for storage purposes it will be seen that the bottom of each head has been labelled with the word TOP. - Instructions for storing British nuclear warheads