Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'string.': 0.04; 'url:pipermail': 0.05; 'exist.': 0.09; 'subject:()': 0.09; 'thread': 0.10; 'python': 0.10; 'index': 0.13; 'argument': 0.15; 'bugs.': 0.16; 'subject:versus': 0.16; 'wrote:': 0.16; 'found,': 0.18; '2015': 0.20; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; '13,': 0.29; 'question:': 0.29; 'str': 0.29; 'problem': 0.33; 'source': 0.33; 'url:python': 0.33; 'doubt': 0.33; 'that,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; '2005': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'hi,': 0.38; 'why': 0.39; 'does': 0.39; "didn't": 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'jul': 0.72; 'python-dev': 0.84; 'to:name:python': 0.84; 'url :python-dev': 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=LshUq0ze9wA3bHSlb0Duf1eebOI12gFrK1QYO7ODh5M=; b=tOGS1RGsbCiWZTIfs3+xNNl364KWfkYeaBOSjLjQBu4KQG5AAH/CGKkTSDe1aV7ahp 55cT10vy2NRbfF6H8j0SLZW/KoMTqg0p4XXjqstg53RwTvRjS/WJGTVPMqxu72ZRv48I z1GQCjTtHhh5q1ciIf8J+G+C7JF6efs/IJFJ5HcSMk4biVvlvqvvGMop5iUuzIXWIHym gSMfeMg8sekg1u1GJRfoKRVOQspzK1UK4AxFa27qgWCnopYgBDWAOm+BXGKGeumK9Fsd 1KsqZ9v+9f4UZ9e06fQYt1beiBgKXvogHSt8pbcNuNooSLr2r+vI3PiaIjTLWvWiB0Cy NQOw== X-Received: by 10.129.94.70 with SMTP id s67mr5956252ywb.111.1436843577279; Mon, 13 Jul 2015 20:12:57 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 13 Jul 2015 21:12:18 -0600 Subject: Re: str.index() and str.find() versus only list.index() To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436843580 news.xs4all.nl 2875 [2001:888:2000:d::a6]:39969 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93771 On Mon, Jul 13, 2015 at 10:56 AM, Roel Schroeven wrote: > Hi, > > Quick question: why does str have both index() and find(), while list only > has index()? Is there a reason for that, or is it just an historical > accident? Historical accident, I think. If it were to be redone, I doubt that str.find would exist. The problem with it is that it returns -1 to indicate that the argument was not found, but -1 is a valid index into the string. This is a potential source of hard-to-find bugs. There was a long thread from 2005 on python-dev proposing to remove str.find in Python 3, but evidently it didn't make the cut: https://mail.python.org/pipermail/python-dev/2005-August/055704.html