Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.058 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'exercise': 0.04; 'method.': 0.07; 'builtin': 0.09; 'high-level': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'algorithmic': 0.16; 'inclined': 0.16; 'libraries.': 0.16; 'subclass': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; 'decide': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'extension': 0.26; 'push': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'wondering': 0.29; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'libraries': 0.31; 'worked': 0.33; 'sense': 0.34; 'problem': 0.35; 'basic': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'building': 0.35; 'there': 0.35; 'really': 0.36; 'subject:List': 0.36; 'doing': 0.36; 'application': 0.37; 'list': 0.37; 'enough': 0.39; 'how': 0.40; 'easy': 0.60; 'hardware': 0.61; 'simple': 0.61; 'first': 0.61; "you'll": 0.62; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'natural': 0.68; 'limit': 0.70; 'obvious': 0.74; 'special': 0.74; 'oscar': 0.84; 'approach.': 0.91; 'directly.': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=MdPvDUGEW4RX/MzIYRIRglyMNlWSJwhMBdYTdDqVVBI=; b=uDxOcD3j41W5jt2eAa+B/8KuMsZftoBM6HLUZZvqRQZTb/RQQB54STKj6Xzb+Qdzpt M5v+lEtzFJt+MElCLOWOJWQzxIqzCtcIlEj4UmrZ51lvSzssv2LWIlQosp8fHl252sk6 qr8kDPYXjQnHTJE1B8vVxRfLMXfJMIqQgoqgCVYQdOknN58I6QouzqB4eav8OuM2XDhw b4+dfWgwzi2UjXrTHv606lQnCs2uwYSuqjVc7OPhNJb5Ri+8whUwPOTw8afpS6Woycdl jzty6bTk0vU4IVqKFce6DjtPJloNWSfeb/pPiqE15x8ej6myF8V5Y9Uhi7g4xycwOq2O U+GA== X-Received: by 10.52.155.141 with SMTP id vw13mr1928263vdb.43.1366646792949; Mon, 22 Apr 2013 09:06:32 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51755C38.4000204@nowhere.org> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> From: Oscar Benjamin Date: Mon, 22 Apr 2013 17:06:12 +0100 Subject: Re: List Count To: Blind Anagram Content-Type: text/plain; charset=ISO-8859-1 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366646795 news.xs4all.nl 2218 [2001:888:2000:d::a6]:44101 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44092 On 22 April 2013 16:50, Blind Anagram wrote: >> >> It would be very easy to subclass list and add this functionality in >> cython if you decide that you do need a builtin method. [snip] > > But I was really wondering if there was a simple solution that worked > without people having to add libraries to their basic Python installations. There are simple solutions and some have already been listed. You are attempting to push your program to the limit of your hardware capabilities and it's natural that in a high-level language you'll often want special libraries for that. I don't know what your application is but I would say that my first port of call here would be to consider a different algorithmic approach. An obvious question would be about the sparsity of this data structure. How frequent are the values that you are trying to count? Would it make more sense to store a list of their indices? If the problem needs to be solved the way that you are currently doing it and the available methods are not fast enough then you will need to consider additional libraries. > > As I have never tried building an extension with cython, I am inclined > to try this as a learning exercise if nothing else. I definitely recommend this over writing a C extension directly. Oscar