[Tutor] beginsWith multiple prefixes

Emad Nawfal (عماد نوفل) emadnawfal at gmail.com
Thu Dec 25 14:31:51 CET 2008


On 12/25/08, Kent Johnson <kent37 at tds.net> wrote:
>
> On Wed, Dec 24, 2008 at 4:04 PM, Emad Nawfal (عماد نوفل)
> <emadnawfal at 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
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081225/5bf25a97/attachment-0001.htm>


More information about the Tutor mailing list