On Jan 21, 4:23 pm, Scott David Daniels <scott.dani...@acm.org> wrote:
> prueba...@latinmail.com wrote:
> > ... If you have duplicates this will not work. You will have to do
> > something like this instead:
>
> >>>> o=[]
> >>>> i=0
> >>>> ln=len(l)
> >>>> while i<ln:
> >    if l[i]['title']=='ti':
> >            o.append(l.pop(i))
> >            ln-=1
> >    else:
> >            i+=1
>
> Or the following:
>      indices = [i for i,d in enumerate(l) if d['title']=='ti']
>      for i in reversed(indices): # so del doesn't affect later positions
>          del l[i]
>
> --Scott David Daniels
> scott.dani...@acm.org

Cool. How come I didn't think of that! That means I can create an evil
one liner now >:-).

replacecount=len([o.append(l.pop(i)) for i in reversed(xrange(len(l)))
if l[i]['title']=='ti'])
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to