Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76501
| 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 | <ian.g.kelly@gmail.com> |
| 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; 'algorithm': 0.04; 'subject:Python': 0.06; 'algorithms,': 0.07; 'elements.': 0.07; 'function,': 0.09; 'stl': 0.09; 'python': 0.11; 'elements).': 0.16; 'sorting': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'aug': 0.22; 'mon,': 0.24; 'sort': 0.25; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'sets': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'url:wikipedia': 0.31; 'anyone': 0.31; 'maybe': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'c++': 0.36; 'url:org': 0.36; 'too': 0.37; 'easily': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'according': 0.40; 'even': 0.60; "you're": 0.61; 'information': 0.63; 'kind': 0.63; 'more': 0.64; 'beat': 0.68; 'default': 0.69; 'partial': 0.84; 'url:tech': 0.84 |
| 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=akFsSG2Kb69Lt3S+FSEr6bqdWNKcARJK8nxJ6FFxJBI=; b=Wy+eiPo+uohrR0mHqdc5cGCHCgn3JffnpaJ43zUWad2JQLEhwtmP8bKqgG6Nat+myx M0nwzpnQg+uadciSNkptsRce58JjnuN3rWE9xiVxP+k2GN8k+j7UFIGjNBjECYWWZeyj c21uO1cn64vCBnqUGq7TKkpzw2ObO3e4m3lFzy7nbAb28V+JO49QV+6tV8CQ7htVeL19 J6R60G7AuMfoPvmN17bEgfVak7tzh9KRiU3kUzqynSM8jcFjgXO/EpbiGsqIj62XeiOe AydSWXwI6W1xJLALgfbuUpAV+rJMOyfo542zUwDTUB7VqHCmr/FsmvQn1W1AgOl20/TY /yXg== |
| X-Received | by 10.66.243.6 with SMTP id wu6mr6921785pac.157.1408387724188; Mon, 18 Aug 2014 11:48:44 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> |
| References | <51dfbe9b-f6e0-4532-bc2d-e7ce2fc282b5@googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 18 Aug 2014 12:48:04 -0600 |
| Subject | Re: efficient partial sort in Python ? |
| To | Python <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 <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.13109.1408387733.18130.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1408387733 news.xs4all.nl 2950 [2001:888:2000:d::a6]:49441 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:76501 |
Show key headers only | View raw
On Mon, Aug 18, 2014 at 11:18 AM, Chiu Hsiang Hsu <wdv4758h@gmail.com> wrote: > I know that Python use Timsort as default sorting algorithm and it is efficient, > but I just wanna have a partial sorting (n-largest/smallest elements). > > In the current state, I can only find this kind of functions from heapq, > but it's too slow for this problem, > the pure c sorted function can easily beat heapq.nlargest even though it sort all the elements. > > I think it would be better if we have an effeicient partial sorting function, > maybe it could be like this : partial_sorted(data, n), data.partial_sort(n) > > Does anyone have any more information for partial sorting ? > > Btw, C++ has a partial_sort function in <algorithm>, but I don't know what algorithm it really use. According to http://www.sgi.com/tech/stl/partial_sort.html the STL implementation also uses heapsort. For better partial sorting algorithms, try Wikipedia: http://en.wikipedia.org/wiki/Partial_sorting However, I think you're still not likely to beat Timsort for smallish data sets unless you also implement it in C.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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