-1

The job is to return a list back as a unique list. However my code doesn't work correctly.

def unique_list(lst):
    d=(lst)
    print(d)

When I enter unique_list([1,1,1,1,2,2,3,3,3,3,4,5]), it returns the same thing. But when I do print(d) on a new cell, it returns the unique numbers. I'm just confused why.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Aaewatech
  • 17
  • 1
  • 1
    it is not clear what you want to achieve, can you be more specific what you mean by "unique list"? – lmiguelvargasf Sep 10 '19 at 20:24
  • @lmiguelvargasf presumably no duplicate characters. Try seeing https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists – Erin B Sep 10 '19 at 20:25
  • What do you mean "when I use print(d) on a new cell"? What is a "new cell"? When you wrap something in parentheses, you're just making it a tuple. This should in now way remove duplicate items. You may be confusing it with `set()` which DOES return only unique items – G. Anderson Sep 10 '19 at 20:25
  • @Aaewatech, it would be nice if you can provide an example of the input and the output you want to get. – lmiguelvargasf Sep 10 '19 at 20:27
  • 3
    Possible duplicate of [Removing duplicates in lists](https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists) – buran Sep 10 '19 at 20:28

1 Answers1

1

Pretty sure this is what you are looking for:

example = [1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5]

def unique_list(list_):
    return list(set(list_))

print(unique_list(example))
Clade
  • 966
  • 1
  • 6
  • 14