Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'indices': 0.07; 'string': 0.09; 'false.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'lawrence': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; '11:09': 0.16; 'slice,': 0.16; 'subject:bit': 0.16; 'exception': 0.16; 'index': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'characters': 0.30; 'code': 0.31; 'extract': 0.31; 'run': 0.32; 'problem': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'problems.': 0.60; 'received:173': 0.61; "you're": 0.61; "you'll": 0.62; "you've": 0.63; 'sample': 0.67; 'received:69.56': 0.68; 'ethan': 0.84; 'furman': 0.84; 'received:gateway02.websitewelcome.com': 0.91 Date: Thu, 13 Feb 2014 11:25:15 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A curious bit of code... References: <4cc09129-43ee-4205-a24c-03f92b594abc@googlegroups.com> <52FD1B01.80200@stoneleaf.us> In-Reply-To: <52FD1B01.80200@stoneleaf.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:33836 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 3 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392319505 news.xs4all.nl 2922 [2001:888:2000:d::a6]:60381 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66212 On 02/13/2014 11:20 AM, Ethan Furman wrote: > On 02/13/2014 11:09 AM, Mark Lawrence wrote: >> >> All I can say is that if you're worried about the speed of a single >> line of code like the above then you've got problems. Having said >> that, I suspect that using an index to extract a single character >> has to be faster than using a slice, but I haven't run these through >> a profiler yet :) > > The problem with using indices in the code sample is that if the > string is 0 or 1 characters long you'll get an exception instead > of a False. Oops, make that zero characters. ;) -- ~Ethan~