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 :
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))