0

why does this code give: [2, 3, 5, 56, 7, 8, 4]

https://code.sololearn.com/c0HoLCAmaTFR/?ref=app I would like that if there are two identical values ​​in the list, then it removes them. But it turns out that the code only deletes the first value and the second does not I want to output: [2, 3, 5, 56, 7, 8] When you enter 4

10th Jun 2021, 1:31 PM
SammE
SammE - avatar
5 odpowiedzi
+ 1
Rostislav Khalilov remove() function will remove only 1st occurance. You can do like this: x1 = 4 x = [2, 3, 4, 5, 56, 7, 8, 4] y = [] [y.append(i) for i in x if i != x1] print (y)
10th Jun 2021, 1:35 PM
A͢J
A͢J - avatar
0
🅰🅹 🅐🅝🅐🅝🅣 or you can do it with the remove () function?
10th Jun 2021, 1:44 PM
SammE
SammE - avatar
0
🅰🅹 🅐🅝🅐🅝🅣 but how to swap the largest element of the list with the smallest?
10th Jun 2021, 3:06 PM
SammE
SammE - avatar
0
Rostislav Khalilov Do you want to swap or sort elements? If you want to sort then do this y.sort() print (y)
10th Jun 2021, 4:50 PM
A͢J
A͢J - avatar