jyjyjyjyjyjjyjyj
jyjyjyjyjyjjyjyj

Reputation: 59

how can I generate the list of elements of list with duplicated elements

for example if I have a list like this :

list =['a','a','a','b','b','b','c']

I want to know how many different elements are in my list and generate a list like this:

list1 = ['a','b','c'] 

Upvotes: 0

Views: 34

Answers (2)

Tamilselvan
Tamilselvan

Reputation: 26

full_list = ["a", "b", "a", "c", "c"]
list_without_duplicaion = list(dict.fromkeys(full_list))
print(list_without_duplicaion)

Try out this answer and let me know is working as your expectations.

https://repl.it/@TamilselvanLaks/arrwithoutdup

Upvotes: 1

Shadesfear
Shadesfear

Reputation: 749

set(list)

produces

>>> set(list)
{'b', 'a', 'c'}

If you then want it as a list you can use

list(set(list))

Upvotes: 2

Related Questions