On 12/25/08, Kent Johnson <ken...@tds.net> wrote:
>
> On Wed, Dec 24, 2008 at 4:04 PM, Emad Nawfal (عماد نوفل)
> <emadnaw...@gmail.com> wrote:
> > Hi Tutors,
> > I want a function that acts like the startswith method, but can take
> > multiple prefixes. As an amateur programmer, I came up with this one, and
> it
> > works fine, but my experience tells me that my solutions are not always
> the
> > best ones around. Can you please tell me what a better option might be:
>
>
> Since Python 2.5, startswith() accepts a tuple as the match parameter,
> so you can write
> def beginsWith(word, listname):
>   return word.startswith(tuple(listname))
>
> or just us startswith() directly.
>
>
> Kent
>

Thank you Kent. I read the documentation, but did not notice it, now I can
see it clearly. This also applies to endswith
Thank you all for your helpfulness.

-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com
--------------------------------------------------------
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to