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


Groups > comp.lang.python > #76609

Re: efficient partial sort in Python ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'algorithm': 0.04; 'cpython': 0.05; 'subject:Python': 0.06; 'float': 0.07; 'pypy': 0.07; 'already.': 0.09; 'dan': 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; 'elements).': 0.16; 'heapq': 0.16; 'pypy?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sorting': 0.16; 'usage,': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; "hasn't": 0.19; '>>>': 0.22; 'code,': 0.22; 'memory': 0.22; 'aug': 0.22; 'header:User-Agent:1': 0.23; 'mon,': 0.24; 'compare': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; '(like': 0.30; 'especially': 0.30; 'code': 0.31; 'another': 0.32; 'guess': 0.33; 'problem': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'ordered': 0.36; 'thanks': 0.36; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'anything': 0.39; 'does': 0.39; 'heard': 0.39; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'august': 0.61; 'pick': 0.64; 'more': 0.64; 'default': 0.69; '3.4': 0.84; 'answer:': 0.84; 'flexibility,': 0.84; 'partial': 0.84; 'partially': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: efficient partial sort in Python ?
Date Tue, 19 Aug 2014 18:11:43 -0400
References <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> <mailman.13116.1408398154.18130.python-list@python.org> <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-71-175-90-87.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <3fb3b4d1-a7e2-4912-a878-7d5e1798aee6@googlegroups.com>
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.13168.1408486351.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408486351 news.xs4all.nl 2925 [2001:888:2000:d::a6]:47572
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76609

Show key headers only | View raw


On 8/19/2014 3:37 PM, Chiu Hsiang Hsu wrote:
> On Tuesday, August 19, 2014 5:42:27 AM UTC+8, Dan Stromberg wrote:
>> On Mon, Aug 18, 2014 at 10:18 AM, Chiu Hsiang Hsu
>> <wdv4758h@gmail.com> wrote:
>>
>>> I know that Python use Timsort as default sorting algorithm and
>>> it is efficient,

Especially with data that is partially ordered already.

>>> but I just wanna have a partial sorting (n-largest/smallest
>>> elements).

>> Perhaps heapq with Pypy?  Or with nuitka?  Or with numba?

> I heard of PyPy and numba before, but I doesn't know nuitka, thanks
> for your information.
>
> Another problem with heapq is the memory usage, it cost a lot of more
> memory with heapq in CPython (I test it in 3.4 with 1000000 float
> numbers) compare to sorted.
>
> For curiosity, there are many speed up solution in Python (like
> Cython, PyPy), I hasn't use Cython before, I guess PyPy is a more
> convient way to speed up current Python code (?), so how does Cython
> compare to PyPy ? (speed, code, flexibility, or anything else)

Why are you rejecting the previous answer: use .sort and pick out 
whatever items you want?


-- 
Terry Jan Reedy

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


Thread

efficient partial sort in Python ? Chiu Hsiang Hsu <wdv4758h@gmail.com> - 2014-08-18 10:18 -0700
  Re: efficient partial sort in Python ? Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-18 12:48 -0600
  Re: efficient partial sort in Python ? Dan Stromberg <drsalists@gmail.com> - 2014-08-18 14:42 -0700
    Re: efficient partial sort in Python ? Chiu Hsiang Hsu <wdv4758h@gmail.com> - 2014-08-19 12:37 -0700
      Re: efficient partial sort in Python ? Terry Reedy <tjreedy@udel.edu> - 2014-08-19 18:11 -0400
      Re: efficient partial sort in Python ? Dan Stromberg <drsalists@gmail.com> - 2014-08-19 16:05 -0700
      Re: efficient partial sort in Python ? Dan Stromberg <drsalists@gmail.com> - 2014-08-19 16:10 -0700
      Re: efficient partial sort in Python ? Dan Stromberg <drsalists@gmail.com> - 2014-08-19 16:22 -0700
      Re: efficient partial sort in Python ? Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-19 18:00 -0600

csiph-web