+ 3

How delete element of list?

I want to write the code, which of the list will delete the element. Help me figure out why my code does not work, or suggest your own code. https://code.sololearn.com/chiU3zOeMYRg/?ref=app

29th Jan 2018, 9:27 AM
Andy Theodorko
Andy Theodorko - avatar
5 Antworten
+ 8
Yep, the best to use filter. If not: l = [1, 1, 3, 2, 1, 3] del_element = 1 while del_element in l: l.remove(del_element) print(l) >>> [3, 2, 3]
29th Jan 2018, 10:02 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
l.remove(1)
29th Jan 2018, 9:49 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar
+ 5
What do you want to delete exactly? One element of a given index or *all* elements equal to a given value?
29th Jan 2018, 9:35 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
I found the answer using the lambda function))) https://code.sololearn.com/cpHy5X7itX24/?ref=app
29th Jan 2018, 10:01 AM
Andy Theodorko
Andy Theodorko - avatar
+ 2
I want to delete all items that are equal to 1
29th Jan 2018, 9:38 AM
Andy Theodorko
Andy Theodorko - avatar