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

Finding minimum excludant of a set

I am a total beginner in Python.
Can’t figure out why the following doesn’t work when I am trying to find the minimum excludant of the given set.

def mex(my_list):
    my_list = set(my_list)
    mex = 0
    while mex in my_list:
        mex += 1
    return mex

a = [1, 0, 2, 4]
print(mex(a))

>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

Your return needs to be indented and you need a ":" after the while statement.

def mex(my_list):
    my_list = set(my_list)
    mex = 0
    while mex in my_list:
        mex += 1
    return mex

a = [1, 0, 2, 4]
print(mex(a))
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