+1

[Solved]Is there any function to create unique item in a list?

11/12/2019 1:37:41 PM

Subham

7 Answers

New Answer

+7

in the code: set(my_list) Set here is a function as you've used the round parentheses on it, so the function would convert it's argument "my_list" to a set data-type

+4

It would be also possible to use a comprehension: lst = [1, 2, 3, 1, 2, 5, 9, 6, 7, 8] res2 = [] [res2.append(item) for item in lst if item not in res2] print(res2)

+2

What do you mean? If you want to remove duplicates from list, use sets: my_list = [5, 7, 7, 4, 3, 5, 7] new_list = list(set(my_list)) print(new_list) # [5, 7, 4, 3]

+2

set? Is that a function or type conversion

+1

set(my_list) is this function or type conversion?

+1

set is an iterable similar to tuples, lists or strings. But in a set the index position is not relevant. Sets are derived of the theory of sets. You can create intersection sets or union sets. One property of sets is the fact that every element is included once. By converting a list with multiple identical elements into a set, an reconverting this set into a list, you can eliminate the multiple elements so that only one of every type remains. Disadvantage of this method is that the initial index position of the elements of your original list gets lost.

0

I didn't understood your question, actually