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

Ron Adam ron3200 at gmail.com
Thu Mar 26 04:36:04 CET 2015



On 03/25/2015 09:45 PM, pedro santos 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.

This is probably the fastest way to remove N items from the end.

 >>> L = list("123456789")
 >>> L
['1', '2', '3', '4', '5', '6', '7', '8', '9']
 >>> L[-3:] = []
 >>> L
['1', '2', '3', '4', '5', '6']

Cheers,
    Ron



More information about the Python-ideas mailing list