Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'python,': 0.02; 'discard': 0.07; 'cc:addr:python-list': 0.11; 'block.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'limit.': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'subject:like': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'container': 0.31; 'fri,': 0.33; 'could': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'similar': 0.36; 'so,': 0.37; 'too': 0.37; 'turn': 0.37; 'list': 0.37; 'easily': 0.37; 'implement': 0.38; 'easiest': 0.38; 'nov': 0.38; 'pm,': 0.38; 'anything': 0.39; 'either': 0.39; 'length': 0.61; 'simply': 0.61; 'to:none': 0.92; 'wanting': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=LGfdeAkvZGFF54a5FBWjMYboGytt/QeCqoEEBarsvn8=; b=cXUo3Xf8rlYwGG8gneWl6LD17gBeBCZ7twz3f5poidTCJSPM9fswIGv1dEgsv8wkl6 /XFOMqN3guVPeXB8xj0Ow8PYcXdCZ/lL0e8GKdAjYQXajwXaIzmKRTV9eVIlyzBGvLWF VN7V/DAysT80QAmhm13dgblUipd6hBQHBEx/YyR8lkwasPNuw2G2lwzVqSPBnlFqSFgd YUtxc8royQ9KeDvYchkaAcZqA128zCzvgOxr6d1+oQ47OQaFvz7W5nLJ9zgOYVngCHh9 P1VwXBTc2bjcjueTjC5P2RkFgFFRWgkVhLuoJe1qfL0NFoo4p8smSX1nxHjciZfKpAql ROvA== MIME-Version: 1.0 X-Received: by 10.66.148.97 with SMTP id tr1mr24688613pab.163.1385690580362; Thu, 28 Nov 2013 18:03:00 -0800 (PST) In-Reply-To: References: Date: Fri, 29 Nov 2013 13:03:00 +1100 Subject: Re: how to implement a queue-like container with sort function From: Chris Angelico Cc: python-list@python.org Content-Type: text/plain; charset=UTF-8 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385690583 news.xs4all.nl 15880 [2001:888:2000:d::a6]:47585 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60749 On Fri, Nov 29, 2013 at 12:54 PM, iMath wrote: > the container is similar to queue ,but queue doesn't have a sort function It's either a queue that can be sorted, or a list with a length limit. You could fairly easily implement either, because in Python, anything can be subclassed. But I think possibly the easiest way is to simply turn your queue into a list when you want to work with it: >>> import queue >>> a=queue.Queue(10) >>> a.put("asdf") >>> a.put("qwer") >>> a.put("zxcv") >>> a.put("1234") >>> sorted(a.queue) ['1234', 'asdf', 'qwer', 'zxcv'] Though I don't know if this is what you meant. Putting too much onto a queue.Queue will block. Were you wanting it, instead, to discard entries? If so, which? ChrisA