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!
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)