Home  >  Article  >  Backend Development  >  Python list removes all specified elements

Python list removes all specified elements

不言
不言Original
2018-04-19 10:52:174849browse

The following is a method to share with you a python list to delete all specified elements. It has a good reference value and I hope it will be helpful to everyone. Come and take a look together

As shown below:

a = [1,1,1,2,3,45,1,2,1]
a.remove(1) 
result: [1,1,2,3,45,1,2,1]

while 1 in a:
a.remove(1)
result: [2,3,45,2]

Related recommendations:

How to delete files and directories in python

Detailed description of Python list sorting methods reverse, sort, sorted


The above is the detailed content of Python list removes all specified elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn