list IndexError

Ishwor ishwor.gurung at gmail.com
Wed Dec 22 22:42:13 CET 2004


On Thu, 23 Dec 2004 07:27:52 +1000, Egor Bolonev <ebolonev at mail.ru> wrote:
> On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <ishwor.gurung at gmail.com> wrote:
> 
> >>>> l
> > ['a', 'b', 'c', 'd', 'e']
> >>>> for x in l[:]:
> >        if x == 'd':
> >                l.remove('d');
> >
> >>>> l
> > ['a', 'b', 'c', 'e']
> > This code is so clean and looks very healthy.  Python will live a
> > long way because its a cute language.
> 
> imho the code is very unhealthy, i would write
> l = ['a', 'b', 'c', 'd', 'e']
> l.remove('d')
> print l
> 
> btw what are you using ';' for

I am learning Python. I used 'for' specifically so that i could
iterate over the list and delete the values. It was a dumb one.. thanx
for pointing it out but i specifically wanted to understand how
slicing work. :-)
thanks anyway.

-- 
cheers,
Ishwor Gurung



More information about the Python-list mailing list