1st Set exercise

Screen Link:

My Code:

def unique(a_list):
    return set(a_list)

Correct answer:

def unique(a_list):
    return list(set(a_list))

Why the need for the list() before set()?

Hi @AntnioSDaCunha,

According to the task, we have to create a function that returns a list. Using set(a_list), we render the initial input a_list into a set, and as a result, remove the duplicated items from it, if there are any (because a set is an unordered collection of distinct items). Next, to transform the result back to a list type, we use list(set(a_list)) and then return the resulting list.

1 Like