Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41671 > unrolled thread

Re: problem with function

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2013-03-21 16:04 -0600
Last post2013-03-21 16:04 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: problem with function Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-21 16:04 -0600

#41671 — Re: problem with function

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-03-21 16:04 -0600
SubjectRe: problem with function
Message-ID<mailman.3602.1363903475.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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):
>     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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web