Reputation: 59
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
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
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