Python list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python list

How can I create a function that return the smallest number that is divisible by 3 from a list. Input [‘2’, ‘1’, ‘3’, ‘4’, ‘6’] Output = 3

2nd May 2020, 11:26 AM
Safi
2 Answers
+ 3
You could use list comprehension b=[i for i in list if int(i)%3==0] print(min(b))
2nd May 2020, 11:56 AM
Justus
Justus - avatar
+ 2
Here is the instructions you should follow : 1) Filter the elements of the list so that it only contains the elements which are divisible by 3! 2) Return the smallest number from the list.
2nd May 2020, 11:51 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar