Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Loop. Why it can see only 10 from whole list?

def new_list(lst):
    for i in lst:
        if i%10 == 0:
            return i
        else:
            return False
        
print(new_list([10, 20.0, 25, 30, 40, 98]))

i want to see all numbers from the list that can be divided into 10

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This can also be done with a list comprehension:

def new_list(lst):
    return [x for x in lst if x % 10 == 0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading