Comment on PythonMonk – Learn Python in the browserComments−aroberge13yTried the test to define unique. Wrote def unique(s): return list(set(s)) and it gave assertion errors. Nice presentation ... but incorrect Python implementation.−metaphorm13ymaybe you had a typo? or they have corrected this in the meantime? I just tried this problem and it was error free.def unique(values): """Finds all unique elements of a list. >>> unique([]) [] >>> unique([1, 2, 1]) [1, 2] >>> unique([1, 2, 1, 3, 4, 2]) [1, 2, 3, 4] """ # your code here return list(set(values)) it also works without the coercion to list. return set(values) is fine.−anandology13yThanks for pointing the mistake. Corrected the tests now.Solution to that problem is correct. Sets weren't introduced yet.
Comments
Tried the test to define unique. Wrote
and it gave assertion errors. Nice presentation ... but incorrect Python implementation.maybe you had a typo? or they have corrected this in the meantime? I just tried this problem and it was error free.
def unique(values): """Finds all unique elements of a list.
it also works without the coercion to list. return set(values) is fine.Thanks for pointing the mistake. Corrected the tests now.
Solution to that problem is correct. Sets weren't introduced yet.