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

Python list removes all specified elements

不言
Release: 2018-04-19 10:52:17
Original
5032 people have browsed it

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]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template