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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to