Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'subject:Python': 0.06; 'dan': 0.09; 'latter': 0.09; 'worse': 0.09; 'former,': 0.16; 'heap,': 0.16; 'latter,': 0.16; 'nsmallest': 0.16; 'worst': 0.16; 'index': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'basically': 0.19; 'aug': 0.22; 'putting': 0.22; 'performing': 0.26; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'probably': 0.32; 'good.': 0.35; 'received:google.com': 0.35; 'curious': 0.36; 'doing': 0.36; 'should': 0.36; 'being': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'beat': 0.68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=uKA69RrBCIlVI72zaspMplA+fEYOQJ2dNVm4D9++eGA=; b=IhQSHcOLA102dHH7WsBoJgBxEt77t5Tngdl9ldUgRMEnM53PcUUIo+/iCRCGELN/1j Lm2hkMVEfvbvjfC0iI8GHCTxKm/vQR3E9R6d8facd43RVLQpWNOX6NzTiWvOOPn7Dq4Z cUseKTZsQAQNTN1dBw3L2WDwjLMUCNipS+FerRNfY0EtScpTj1NaFBfksSW9T57zSQNv xXlVIJzZvlCURocQ2z3aoT04tav4YHmPRlOop0roFx7HVOLfv3l7WKsWDW/5zcCD+Dm1 WW7zmvA5uhyVk3jWGYh/OHuRsdpzRpnkWy8/nZOUqAAiBcGeRgu7CaMoNmst8AJ7Mp7K 1Ohg== X-Received: by 10.66.154.234 with SMTP id vr10mr48309051pab.44.1408492900090; Tue, 19 Aug 2014 17:01:40 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com> From: Ian Kelly Date: Tue, 19 Aug 2014 18:00:58 -0600 Subject: Re: efficient partial sort in Python ? To: Python 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: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408492909 news.xs4all.nl 2878 [2001:888:2000:d::a6]:56429 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76627 On Tue, Aug 19, 2014 at 5:05 PM, Dan Stromberg wrote: > When you use heapq, are you putting all the values in the heap, or > just up to n at a time (evicting the worst value, one at a time as you > go)? If you're doing the former, it's basically a heapsort which > probably won't beat timsort. If you're doing the latter, that should > be pretty good. The latter is what the heapq.nsmallest and heap.nlargest functions do. nsmallest uses a max heap, so the value being evicted is still found at index 0. Curious then if it's performing worse memory-wise than sorted.