<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2654.45">
<TITLE>RE: Slicing vs .startswith</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Sorry for not replying the original message.</FONT>
</P>

<P><FONT SIZE=2>See PEP 08:</FONT>
</P>

<P><FONT SIZE=2>    - Avoid slicing strings when checking for prefixes or suffixes.</FONT>
<BR><FONT SIZE=2>      Use startswith() and endswith() instead, since they are faster,</FONT>
<BR><FONT SIZE=2>      cleaner and less error prone.  E.g.:</FONT>
</P>

<P><FONT SIZE=2>        No:  if foo[:3] == 'bar':</FONT>
<BR><FONT SIZE=2>        Yes: if foo.startswith('bar'):</FONT>
</P>

<P><FONT SIZE=2>      The exception is if your code must work with Python 1.5.2 (but</FONT>
<BR><FONT SIZE=2>      let's hope not!).</FONT>
</P>
<BR>

<P><FONT SIZE=2>.       Facundo</FONT>
</P>
<BR>

<P><FONT SIZE=2>#- -----Mensaje original-----</FONT>
<BR><FONT SIZE=2>#- De: David Eppstein [<A HREF="mailto:eppstein@ics.uci.edu">mailto:eppstein@ics.uci.edu</A>]</FONT>
<BR><FONT SIZE=2>#- Enviado el: Lunes 22 de Septiembre de 2003 3:52 PM</FONT>
<BR><FONT SIZE=2>#- Para: python-list@python.org</FONT>
<BR><FONT SIZE=2>#- Asunto: Re: Slicing vs .startswith</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- In article <3F6F3E38.5221D7E7@engcorp.com>,</FONT>
<BR><FONT SIZE=2>#-  Peter Hansen <peter@engcorp.com> wrote:</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- > > For example, which one of the following would be more </FONT>
<BR><FONT SIZE=2>#- efficient, or ,</FONT>
<BR><FONT SIZE=2>#- > > moreover, more pythonic?</FONT>
<BR><FONT SIZE=2>#- > > </FONT>
<BR><FONT SIZE=2>#- > > if aa[:3] == 'abc':</FONT>
<BR><FONT SIZE=2>#- > > </FONT>
<BR><FONT SIZE=2>#- > > vs</FONT>
<BR><FONT SIZE=2>#- > > </FONT>
<BR><FONT SIZE=2>#- > > if aa.startswith('abc'):</FONT>
<BR><FONT SIZE=2>#- > </FONT>
<BR><FONT SIZE=2>#- > The latter is clearly more readable.</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- More Pythonic, too, I think.  "Readability counts," and </FONT>
<BR><FONT SIZE=2>#- "There should be </FONT>
<BR><FONT SIZE=2>#- one-- and preferably only one --obvious way to do it."  In </FONT>
<BR><FONT SIZE=2>#- this case, </FONT>
<BR><FONT SIZE=2>#- startswith must be the one obvious way, or else why would it </FONT>
<BR><FONT SIZE=2>#- exist in </FONT>
<BR><FONT SIZE=2>#- the standard library at all?</FONT>
<BR><FONT SIZE=2>#- </FONT>
<BR><FONT SIZE=2>#- -- </FONT>
<BR><FONT SIZE=2>#- David Eppstein                      <A HREF="http://www.ics.uci.edu/~eppstein/" TARGET="_blank">http://www.ics.uci.edu/~eppstein/</A></FONT>
<BR><FONT SIZE=2>#- Univ. of California, Irvine, School of Information & Computer Science</FONT>
<BR><FONT SIZE=2>#- -- </FONT>
<BR><FONT SIZE=2>#- <A HREF="http://mail.python.org/mailman/listinfo/python-list" TARGET="_blank">http://mail.python.org/mailman/listinfo/python-list</A></FONT>
<BR><FONT SIZE=2>#- </FONT>
</P>
<BR>
<BR>
<BR>
<BR>

<P><B><FONT SIZE=2>. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .</FONT></B></P>

<P><B><U><FONT SIZE=2>ADVERTENCIA </FONT></U> </B>
</P>

<P><B><FONT SIZE=2>La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley. </FONT></B></P>

<P><B><FONT SIZE=2>Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo. </FONT></B></P>

<P><B><FONT SIZE=2>Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada. </FONT></B></P>

<P><B><FONT SIZE=2>Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje. </FONT></B></P>

<P><B><FONT SIZE=2>Muchas Gracias.</FONT></B>
</P>

</BODY>
</HTML>