Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60759

Re: how to implement a queue-like container with sort function

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 <cameron@cskk.homeip.net>
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 <cs@zip.com.au>
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 <cf8a9111-2202-4519-b6aa-48744b5ba198@googlegroups.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <cf8a9111-2202-4519-b6aa-48744b5ba198@googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3393.1385705979.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 28Nov2013 18:04, iMath <redstone-cold@163.com> 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 <cs@zip.com.au>

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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to implement a queue-like container  with sort function iMath <redstone-cold@163.com> - 2013-11-28 17:54 -0800
  Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-11-29 13:03 +1100
    Re: how to implement a queue-like container with sort function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-29 03:32 +0000
  Re: how to implement a queue-like container  with sort function iMath <redstone-cold@163.com> - 2013-11-28 18:04 -0800
    Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-11-29 13:06 +1100
      Re: how to implement a queue-like container with sort function iMath <redstone-cold@163.com> - 2013-11-28 18:32 -0800
    Re: how to implement a queue-like container  with sort function Cameron Simpson <cs@zip.com.au> - 2013-11-29 17:19 +1100
  Re: how to implement a queue-like container  with sort function MRAB <python@mrabarnett.plus.com> - 2013-11-29 02:23 +0000
  Re: how to implement a queue-like container  with sort function Terry Reedy <tjreedy@udel.edu> - 2013-11-28 21:31 -0500
  Re: how to implement a queue-like container  with sort function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-29 17:53 +1300
  Re: how to implement a queue-like container  with sort function iMath <redstone-cold@163.com> - 2013-11-29 04:33 -0800
    Re: how to implement a queue-like container  with sort function Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-29 14:57 +0000
      Re: how to implement a queue-like container  with sort function iMath <redstone-cold@163.com> - 2013-12-02 03:41 -0800
        Re: how to implement a queue-like container  with sort function Ned Batchelder <ned@nedbatchelder.com> - 2013-12-02 06:58 -0500
        Re: how to implement a queue-like container with sort function Chris Angelico <rosuav@gmail.com> - 2013-12-02 23:04 +1100
        Re: how to implement a queue-like container with sort function Ned Batchelder <ned@nedbatchelder.com> - 2013-12-02 07:26 -0500

csiph-web