Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44061
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <blindanagram@nowhere.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'ideally': 0.04; 'list?': 0.07; 'broke': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; 'creates': 0.14; '(say': 0.16; 'be:': 0.16; 'boolean': 0.16; 'bytearray': 0.16; 'iterators': 0.16; 'itertools': 0.16; 'notation,': 0.16; 'sub-class': 0.16; 'elements': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'extension': 0.26; 'possibly': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'fastest': 0.30; 'sets': 0.30; "i'm": 0.30; 'lines': 0.31; 'copying': 0.34; 'could': 0.34; 'problem': 0.35; 'advice': 0.35; 'something': 0.35; 'hundreds': 0.35; 'but': 0.35; 'there': 0.35; 'grateful': 0.36; 'subject:List': 0.36; "i'll": 0.36; 'possible': 0.36; 'so,': 0.37; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'problems': 0.38; 'lists.': 0.38; 'somebody': 0.38; 'aspects': 0.39; 'sure': 0.39; 'dave': 0.60; "you're": 0.61; 'offer': 0.62; 'interest': 0.64; 'provide': 0.64; 'more': 0.64; 'believe': 0.68; 'default': 0.69; 'costly': 0.84; 'ideas.': 0.84; 'received:192.168.1.7': 0.84; 'angel': 0.91 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=YbCEuWhf c=1 sm=1 tr=0 a=nO6JWm9Dsne7RoCvRGnC0w==:117 a=nO6JWm9Dsne7RoCvRGnC0w==:17 a=0Bzu9jTXAAAA:8 a=fr8gcSRtuOIA:10 a=IVHPnoOXeGEA:10 a=8nJEP1OIZ-IA:10 a=BRpsHpjDAAAA:8 a=sXOIDwgukokA:10 a=-904a8iqSoPJf6TSvUwA:9 a=xlog97aeXKBMYqlo:21 a=Kr3FQ73rnCONX4XY:21 a=wPNLvfGTeEIA:10 |
| X-AUTH | gladman+brg:2500 |
| Date | Mon, 22 Apr 2013 14:03:25 +0100 |
| From | Blind Anagram <blindanagram@nowhere.org> |
| User-Agent | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.python |
| To | Dave Angel <davea@davea.name> |
| Subject | Re: List Count |
| References | <sridnffI6YhxuOjMnZ2dnUVZ7tSdnZ2d@brightview.co.uk> <mailman.907.1366635127.3114.python-list@python.org> |
| In-Reply-To | <mailman.907.1366635127.3114.python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.910.1366636010.3114.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366636010 news.xs4all.nl 2198 [2001:888:2000:d::a6]:49042 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44061 |
Show key headers only | View raw
On 22/04/2013 13:51, Dave Angel wrote: > On 04/22/2013 07:58 AM, Blind Anagram wrote: >> I would be grateful for any advice people can offer on the fastest way >> to count items in a sub-sequence of a large list. >> >> I have a list of boolean values that can contain many hundreds of >> millions of elements for which I want to count the number of True values >> in a sub-sequence, one from the start up to some value (say hi). >> >> I am currently using: >> >> sieve[:hi].count(True) >> >> but I believe this may be costly because it copies a possibly large part >> of the sieve. >> >> Ideally I would like to be able to use: >> >> sieve.count(True, hi) >> >> where 'hi' sets the end of the count but this function is, sadly, not >> available for lists. >> >> The use of a bytearray with a memoryview object instead of a list solves >> this particular problem but it is not a solution for me as it creates >> more problems than it solves in other aspects of the program. >> >> Can I assume that one possible solution would be to sub-class list and >> create a C based extension to provide list.count(value, limit)? >> >> Are there any other solutions that will avoid copying a large part of >> the list? >> > > Instead of using the default slice notation, why not use > itertools.islice() ? > > Something like (untested): > > import itertools > > it = itertools.islice(sieve, 0, hi) > sum(itertools.imap(bool, it)) > > I only broke it into two lines for clarity. It could also be: > > sum(itertools.imap(bool, itertools.islice(sieve, 0, hi))) > > If you're using Python 3.x, say so, and I'm sure somebody can simplify > these, since in Python 3, many functions already produce iterators > instead of lists. Thanks, I'll look at these ideas. And, yes, my interest is mainly in Python 3.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 12:58 +0100
Re: List Count Dave Angel <davea@davea.name> - 2013-04-22 08:51 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 14:03 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 14:03 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 13:13 +0000
Re: List Count Skip Montanaro <skip@pobox.com> - 2013-04-22 08:57 -0500
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 15:15 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 16:14 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 16:50 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 17:06 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 17:38 +0100
Re: List Count Skip Montanaro <skip@pobox.com> - 2013-04-22 12:48 -0500
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 20:22 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 21:18 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 22:25 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 00:06 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 07:45 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 23:28 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:00 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-22 22:03 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 22:32 +0100
Re: List Count Dave Angel <davea@davea.name> - 2013-04-22 21:47 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:02 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 17:38 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-22 16:50 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 23:01 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 08:05 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 12:08 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 12:45 +0100
Re: List Count Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-23 15:01 -0400
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 14:49 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 17:57 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 18:45 +0100
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 19:30 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 20:16 +0100
Re: List Count Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-23 16:00 -0400
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-23 21:41 +0100
Re: List Count Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-23 21:38 +0100
Re: List Count Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-24 01:59 +0000
Re: List Count Blind Anagram <blindanagram@nowhere.org> - 2013-04-24 10:01 +0100
Re: List Count Peter Otten <__peter__@web.de> - 2013-04-22 15:22 +0200
Re: List Count 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-22 06:36 -0700
csiph-web