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
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
Hi Ron Wasn't looking for the n items from the end but good to know.
Cheers
On Thu, Mar 26, 2015 at 3:36 AM, Ron Adam ron3200@gmail.com wrote:
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
Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
On 26.03.15 05:36, Ron Adam wrote:
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']
del L[-3:]