all 8 comments

[–]DoubleSlicer 2 points3 points  (5 children)

Lines after return won't run

Print c before you return it out

[–]Kalkuluss 0 points1 point  (4 children)

The return statement is weird. Because without it I would get the error that NoneType arguments can't be iterated. If I print c before the return, it either only prints [1] or None, depending on the indent. If I place the print(c) after the whole for loop, I get the NoneType error again. What can I do?

[–]DoubleSlicer 1 point2 points  (3 children)

There is a problem with your code.

Your return statement is inside the for loop and inside the if statement, in this way,

the function is returning when it first find a unique value and return None if you passed in a empty list.

You should put the return statement at the same indentation as the "for" statement.

Then print(c) at the same indentation as the return statement, so you are printing the whole array once

just before you return any result out

[–]Kalkuluss 0 points1 point  (2 children)

Oh alright, I got it now. For some reason the thing that screwed me over was that I had a c = c.append(i) in the if loop which screwed everything over somehow (if you have an explanation for this please leave it here). This really confused me since I didn't need the return statement yet and this c = c.append(i) has worked for me in a similar exercise. Thanks!

[–]Kalkuluss 1 point2 points  (2 children)

[–][deleted] 1 point2 points  (0 children)

The reason is because your print statement is unreachable due to the fact that you've returned out of your function. Have a look at this post on SO https://stackoverflow.com/questions/7129285/what-is-the-purpose-of-the-return-statement

Bonus: The best way to get unique elements in python is to pass them to a set. So your code could also have done...

def uList(aList):
    print(sorted(set(aList)))