Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41671
| References | <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> |
|---|---|
| Date | 2013-03-21 16:04 -0600 |
| Subject | Re: problem with function |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3602.1363903475.2939.python-list@python.org> (permalink) |
[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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: problem with function Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-21 16:04 -0600
csiph-web