Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'parameters': 0.04; 'occurrences': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'first:': 0.16; 'reedy': 0.16; 'true:': 0.16; 'index': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'returned': 0.30; 'said,': 0.30; 'start,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'there.': 0.32; 'interface': 0.32; 'common': 0.35; 'except': 0.35; 'received:google.com': 0.35; 'subject:List': 0.36; 'yield': 0.36; 'doing': 0.36; 'method': 0.36; 'being': 0.38; 'rather': 0.38; 'more': 0.64; 'oscar': 0.84; '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=xT5RwBEjudhQedsRzd5KRnyIUnfzNG9OseDdq9iz+Ss=; b=NGe6ILgQ45ThKisAOYGx04evSK3AFRoL5lESCBCUBDoclHIXeWB+R4o56YQta5DxEb jFLBM95Fbxw55ln+kt6oQUKJ/CGmVuv7xHFK/61Hzcq+27uh3XAlf2G6cWimBoRcqMR5 tqcUYkAS6HddhV9kScLWbvmGGfsV/Ga9fPZIrfesRXP4nK9n1fyHs82UJ378AZ7gXCyT CwpCs/cWfu362AZCCpfji4nYfdbE+xWtXTNs/PvzSlspO5f6S7H+T4hLG3piMkdhISAN eETb/rzrUHBH0PBO1UGBTzSV97J3tOzhI2L38x1NwkkP7VjnYJuBw6GrsdNzMli5+KlN EVDQ== X-Received: by 10.58.180.196 with SMTP id dq4mr7901149vec.10.1366749538976; Tue, 23 Apr 2013 13:38:58 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> From: Oscar Benjamin Date: Tue, 23 Apr 2013 21:38:38 +0100 Subject: Re: List Count To: Terry Jan Reedy 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366749953 news.xs4all.nl 2311 [2001:888:2000:d::a6]:58226 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44213 On 23 April 2013 21:00, Terry Jan Reedy wrote: > > That said, I do see that tuple/list.index have had start, stop paramaters > added, so doing the same for .count is conceivable. Are those new? I don't remember them not being there. You need the start/stop parameters to be able to use index for finding all occurrences of an item rather than just the first: def indices(value, sequence): i = -1 while True: try: i = sequence.index(value, i + 1) except ValueError: return yield i I thought this was a common use case for .index() and that if the interface had been designed more recently then it might have just been an .indices() method that returned an iterator. Oscar