problem with function
Ian Kelly
ian.g.kelly at gmail.com
Thu Mar 21 18:04:26 EDT 2013
On Mar 21, 2013 1:35 PM, "leonardo selmi" <l.selmi at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130321/86ddf16a/attachment.html>
More information about the Python-list
mailing list