0

how can I remove various items of a list?

Hello, I have an example. list=['p', 'q', 'u', 's', 'p', 'u'] list.remove('u') # it just removes first 'u' print(list) ['p', 'q', 's', 'p', 'u'] How can I remove all 'u' items in the list? Thanks!

12th Apr 2019, 9:10 PM
Rodrigo Lozano
Rodrigo Lozano - avatar
1 Odpowiedź
+ 1
Here you go, the answer is by using a list comprehension lists = ["a","u","c","a","a"] lists = [x for x in lists if x is not "a"] print(lists)
12th Apr 2019, 9:25 PM
Dlite
Dlite - avatar