[Python-ideas] list.pop() accepting a list of integers as argument

pedro santos probiner at gmail.com
Thu Mar 26 03:39:38 CET 2015


Hi David
Thanks for the idea. Just some considerations:

- Del is a list with indices and not the items themselves, so if you
replace the code with that line it won't output the same result.
- *del *deletes all items with an equal value so if I have L=[2,2,2,1,2]
and have Del=[2], I end up with L=[1], which useful, but not my goal here
and the reason I went to pop() instead, so I can address indices. Same
remark for *in*.
- I wouldn't mind if* in* and *del* approach would work if you instead of
checking the value would be checking if a list had such indices and then
deleting all at the same time if so.

Again the same code with comments. http://repl.it/f6E/3

Thanks



On Thu, Mar 26, 2015 at 2:04 AM, David Blaschke <dwblas at gmail.com> wrote:

> ist comprehension is straight forward IMHO, and possibly faster than
> pop depending on whether the items are removed one at a time or just
> marked for deletion later
> new_list=[item for item in L if item not in Del]
>
> On 3/25/15, pedro santos <probiner at gmail.com> wrote:
> > Is this best way to remove multiple items from a list?
> > Because if so I think passing a list of integers through pop would be
> > cleaner.
> >
> > Code here: http://repl.it/f6E
> >
> > Cheers
> >
> >
> >
> >
> > --
> >
> >
> >
> >
> > *------------------------------[image:
> > http://i153.photobucket.com/albums/s202/animatics/probiner-sig.gif]Pedro
> > Alpiarça dos Santos Animator  3DModeler  Illustrator >>
> > http://probiner.x10.mx/ <http://probiner.x10.mx/>*
> >
>
>
> --
> Only when you actually get to the state where there is neither
> delusion nor enlightenment are you finally comfortable...Foyan
>



-- 




*------------------------------[image:
http://i153.photobucket.com/albums/s202/animatics/probiner-sig.gif]Pedro
Alpiarça dos Santos Animator  3DModeler  Illustrator >>
http://probiner.x10.mx/ <http://probiner.x10.mx/>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150326/007ce133/attachment.html>


More information about the Python-ideas mailing list