Why doesnโ€™t it work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why doesnโ€™t it work?

def remove_smallest(numbers): c = min(numbers) numbers.remove(c) return numbers

23rd Aug 2020, 4:17 PM
Aleksandra Lewandowska
Aleksandra Lewandowska - avatar
4 Answers
+ 2
If numbers is a list, then you should not mutate (change) it, because that might mess with the test validation. Make a copy or use a list comprehension.
23rd Aug 2020, 7:52 PM
Tibor Santa
Tibor Santa - avatar
0
What wrong you getting there? Post full code..
23rd Aug 2020, 4:20 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
0
Jayakrishna๐Ÿ‡ฎ๐Ÿ‡ณ โ™คโ™ขโ˜ž ๐Š๐ข๐ข๐›๐จ ๐†๐ก๐š๐ฒ๐š๐ฅ โ˜œโ™ขโ™ค Itโ€™s a kata from codewars. Itโ€™s supposted to remove the smallest number from the list, but it produces an error and I donโ€™t know why
23rd Aug 2020, 5:57 PM
Aleksandra Lewandowska
Aleksandra Lewandowska - avatar
0
What is the error you not mentioned? Aleksandra Lewandowska If this is full code, then you are defined function. But not calling that function to work.. So it should be like def remove_smallest(numbers): c = min(numbers) numbers.remove(c) return numbers l = [1,2,3,4,5] #an example, you take here input. print( remove_smallest(l)) #calling function, displays return list #Output : [2,3,4,5]
23rd Aug 2020, 8:35 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ