Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93775
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'bug.': 0.07; 'correct.': 0.07; 'interpreted': 0.07; 'raises': 0.07; 'exist.': 0.09; 'subject:()': 0.09; 'exception': 0.13; 'index': 0.13; 'argument': 0.15; '"using': 0.16; 'bugs.': 0.16; 'index.': 0.16; 'subject:versus': 0.16; 'wrote:': 0.16; 'string': 0.17; 'found,': 0.18; '>>>': 0.20; '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; 'possibly': 0.32; 'problem': 0.33; 'source': 0.33; "d'aprano": 0.33; 'doubt': 0.33; 'steven': 0.33; 'tue,': 0.34; 'that,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'returning': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'anything': 0.38; 'hi,': 0.38; 'why': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'skip:n 10': 0.62; 'jul': 0.72; 'to:name:python': 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=cElryH7fW/o51IWLHPEDdCrZpsj0XMdJV1yZn/wr4/o=; b=H18Nj+FCZgtc308Kq5eTDmpVhBZsTxciEgzc8qL2I9ZOriJQAEaH3oS2rPPTryxIn+ Ctn8O60SF2U9dI2vQm7dpMPwDHIM0eK/r6cSTAfSeuTfMVcnB2BUbb/HGnG+nmXAup5K yFemfHA6CWKZudOTRfkSEoaj0nkB3qKDUKKY7iLVpI1nzjhXE2F5iKSwKAAXbbHmu5M3 2WY7gFE6I2E2qyvZBO2Q2b+di06YGOrKolaJ4/r0/kLKPZ1ByVcT3cbAPEtrodhX3JAC wCsKXfO+zGYrchu9sev9O0rjqW+onyOgmSrM8hG1M44K5rCmEotW08JBuj5qoV8oF5+G PgEQ== |
| X-Received | by 10.129.88.86 with SMTP id m83mr15385871ywb.147.1436846886390; Mon, 13 Jul 2015 21:08:06 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <55a480c0$0$1673$c3e8da3$5496439d@news.astraweb.com> |
| References | <mo0qk1$ora$1@ger.gmane.org> <mailman.475.1436843580.3674.python-list@python.org> <55a480c0$0$1673$c3e8da3$5496439d@news.astraweb.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 13 Jul 2015 22:07:27 -0600 |
| Subject | Re: str.index() and str.find() versus only list.index() |
| To | Python <python-list@python.org> |
| 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 <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.477.1436846888.3674.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1436846888 news.xs4all.nl 2874 [2001:888:2000:d::a6]:51348 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:93775 |
Show key headers only | View raw
On Mon, Jul 13, 2015 at 9:23 PM, Steven D'Aprano <steve@pearwood.info> wrote: > On Tue, 14 Jul 2015 01:12 pm, Ian Kelly wrote: > >> On Mon, Jul 13, 2015 at 10:56 AM, Roel Schroeven <roel@roelschroeven.net> >> 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. > > Correct. But rather than removing it, it would be better to take a leaf out > of re.match's book and return None as the sentinel. That would eliminate > the "using -1 as a valid index" bug. I disagree on both counts. >>> s = 'abc' >>> s[None:None] 'abc' Better IMO to just have the one non-redundant method that raises an exception rather than returning anything that could possibly be interpreted as a string index.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: str.index() and str.find() versus only list.index() Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-13 21:12 -0600
Re: str.index() and str.find() versus only list.index() Steven D'Aprano <steve@pearwood.info> - 2015-07-14 13:23 +1000
Re: str.index() and str.find() versus only list.index() Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-13 22:07 -0600
Re: str.index() and str.find() versus only list.index() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-07-14 14:58 +1000
Re: str.index() and str.find() versus only list.index() Chris Angelico <rosuav@gmail.com> - 2015-07-14 15:13 +1000
csiph-web