Help needed with "More than N" List Challenge

Hi everyone,

I’m taking the challenges on this page but I got stuck on #4 (“More than N”). I would need your precious help to understand why this piece of code returns “none” instead of “True”.

def more_than_n(lst, item, n):

  lst = []

  item = []

  for i in item:

    if i in lst:

      i += 1

      if i > n:

        return True


        return False  

#Uncomment the line below when your function is done

print(more_than_n([2, 4, 6, 2, 3, 2, 1, 2], 2, 3))

Do you have any clues as to what I’m doing wrong? Is my approach completely wrong?

Thanks a lot, I really appreciate your help!

It looks like you are overriding two of the parameters passed into the function (lst and item) to empty arrays at the very start of the function, so for the entirety of the function they don’t actually store the value passed into the function, they only store an empty array.

Also, you have return inside of a loop which is usually an indicator of an issue, because the return statement stops the iteration of the function, the loop with only ever run once before stopping and never run the rest of the iterations

And since item is an int, you can’t do for i in item as the int datatype is not iterable.


thanks lyallstewart, so my approach was indeed very wrong :sweat_smile:
I didn’t know that the return statement stopped the iteration of the function. I get the point now.
What I didn’t quite get, however, if how lst and item are overriding. Can you help me better understand that?
Thanks a lot!

def more_than_n(lst, item, n):

  lst = []    <=  wipes out `lst`

  item = []  <=  wipes out `item`
1 Like

I think I understand now, it’s because they’re empty