RE: ???? i can`t understand it

Discussion in 'Python' started by Batista, Facundo, Aug 8, 2003.

  1. You're removing elementes from the same list you're iterating: bad, bad
    thing.

    The easiest solution is to make a slice copy of the list and iterate over
    the copied list:

    >>> a = [1,2,3,4,5]
    >>> for b in a[:]:

    a.remove(b)
    >>> a

    []


    .. Facundo



    -----Mensaje original-----
    De: Enrique [mailto:]
    Enviado el: Viernes 8 de Agosto de 2003 5:11 AM
    Para: Python-List
    Asunto: ???? i can`t understand it


    >>> a=[1,2,3,4,5]
    >>> for b in a:

    .... a.remove(b)
    ....
    >>> a

    [2, 4]
    >>>






    .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .
    .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . .
    .. . . . . . . . . . . . . . .
    ADVERTENCIA

    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.

    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.

    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.

    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.

    Muchas Gracias.
    Batista, Facundo, Aug 8, 2003
    #1
    1. Advertising

  2. On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" <> wrote:

    >This message is in MIME format. Since your mail reader does not understand
    >this format, some or all of this message may not be legible.


    If you could eliminate the HTML, it would improve reception on this end ;-)

    Regards,
    Bengt Richter
    Bengt Richter, Aug 8, 2003
    #2
    1. Advertising

  3. Batista, Facundo

    Anand Pillai Guest

    I would rather use slices.
    Here are two ways of doing it.

    >>>a=[1,2,3,4,5]
    >>>for b in a[0:}

    .... a.remove(b)

    >>>print a

    []

    Or I think a better way is (dont ask me why!)
    >>>a=[1,2,3,4,5]
    >>>for b in a[:]:

    .... a.remove(b)

    >>>print a

    []


    -Anand









    (Bengt Richter) wrote in message news:<bh0vr8$1oe$0@216.39.172.122>...
    > On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" <> wrote:
    >
    > >This message is in MIME format. Since your mail reader does not understand
    > >this format, some or all of this message may not be legible.

    >
    > If you could eliminate the HTML, it would improve reception on this end ;-)
    >
    > Regards,
    > Bengt Richter
    Anand Pillai, Aug 13, 2003
    #3
  4. Batista, Facundo

    Anand Pillai Guest

    I would rather use slices.
    Here are two ways of doing it.

    >>>a=[1,2,3,4,5]
    >>>for b in a[0:] # Small typo here in prev post

    .... a.remove(b)

    >>>print a

    []

    Or I think a better way is (dont ask me why!)
    >>>a=[1,2,3,4,5]
    >>>for b in a[:]:

    .... a.remove(b)

    >>>print a

    []


    -Anand


    (Bengt Richter) wrote in message news:<bh0vr8$1oe$0@216.39.172.122>...
    > On Fri, 8 Aug 2003 08:05:11 -0300, "Batista, Facundo" <> wrote:
    >
    > >This message is in MIME format. Since your mail reader does not understand
    > >this format, some or all of this message may not be legible.

    >
    > If you could eliminate the HTML, it would improve reception on this end ;-)
    >
    > Regards,
    > Bengt Richter
    Anand Pillai, Aug 13, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil
    Replies:
    11
    Views:
    8,530
    vipinlal
    Mar 11, 2010
  2. =?Utf-8?B?S2VubmV0aCBQ?=

    An error message I can't understand

    =?Utf-8?B?S2VubmV0aCBQ?=, Mar 12, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,843
    Jeff Dillon
    Aug 6, 2008
  3. JV
    Replies:
    1
    Views:
    343
  4. Learner
    Replies:
    1
    Views:
    424
    Kevin Spencer
    Jan 5, 2006
  5. Paul F. Johnson

    I can't understand this problem

    Paul F. Johnson, Oct 12, 2004, in forum: HTML
    Replies:
    2
    Views:
    335
Loading...

Share This Page