is this pythonic?
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Jan 21 16:23:54 EST 2009
pruebauno at 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.Daniels at Acm.Org
More information about the Python-list
mailing list