Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.038 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '21,': 0.07; 'def': 0.10; 'index': 0.13; 'letter:': 0.16; 'wrote:': 0.17; '<': 0.17; 'all,': 0.21; 'subject:problem': 0.22; 'cheers,': 0.23; '>': 0.23; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'message- id:@mail.gmail.com': 0.27; 'skip:& 10': 0.29; 'to:addr:python- list': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'subject:with': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'more': 0.63; '2013': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=DbA3WjYvaiRcUUPkLdv7PzYtanoeHx7PVswMCXi2gCw=; b=A7o37ounGA6BuOlnyE0gW8d7Z36VGQdl3NmnW2P9irSeJlSauMtnAiPVnF7DHyKIXZ tC/FeFBnZrxNpz0cnjgxP1lMo78ulB+lowlMaJ0cUtknqFFGkddFWlx5y4jfj/eJhqlk 3I8z3tf1UCQtznDTwLDvM7sc0fdpxNwRvHBDwfDbdfUDpCLEERMQkpWuzNwEcvs24Ln4 epcJhB/HSJXnpabbjBzXiqdEasHetFc3BadMfG4hzeWzwEQWNgvhcUap1+t+cDSPniXr 4RuX41IajSofEQVqycTcKmYiPh1gnRvMB5QRQ6U+qsJrxNjAfN68Zp1aGhIQMxR4wpVI ig9g== MIME-Version: 1.0 X-Received: by 10.52.76.103 with SMTP id j7mr13784857vdw.90.1363903466923; Thu, 21 Mar 2013 15:04:26 -0700 (PDT) In-Reply-To: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Date: Thu, 21 Mar 2013 16:04:26 -0600 Subject: Re: problem with function From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=bcaec5016233a76cea04d8768539 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363903475 news.xs4all.nl 6876 [2001:888:2000:d::a6]:58839 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:41671 --bcaec5016233a76cea04d8768539 Content-Type: text/plain; charset=ISO-8859-1 On Mar 21, 2013 1:35 PM, "leonardo selmi" wrote: > > hi all, > > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 > More efficient: def find(word, letter): return word.find(letter) Or even: find = str.find Cheers, Ian --bcaec5016233a76cea04d8768539 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Mar 21, 2013 1:35 PM, "leonardo selmi" <l.selmi@icloud.com> wrote:
>
> hi all,
>
> i wrote the following code:
>
> def find(word, letter):
> =A0 =A0 index =3D 0
> =A0 =A0 while index < len(word):
> =A0 =A0 =A0 =A0 if word[index] =3D=3D letter:
> =A0 =A0 =A0 =A0 =A0 =A0 return index
> =A0 =A0 =A0 =A0 index =3D index + 1
> =A0 =A0 return -1
>

More efficient:

def find(word, letter):
=A0=A0=A0 return word.find(letter)

Or even:

find =3D str.find

Cheers,
Ian

--bcaec5016233a76cea04d8768539--