I have a question about my code because I would like to know how I can remove duplicated elements in my code by keeping the first one each time.
As an example is better than many words :
mylist = [a,a,a,b,c,c,a,d,e,e,e]
I would like to get:
my_new_list = [a,b,c,a,d,e]
my_new_list_2 = [a,3,b,1,c,2,a,1,d,1,e,3]
The process is the following:
As soon as I have a letter or the same following letter, I write this letter one time, then it's the same thing for the next letter etc .. Then I need to remove consecutive duplicates and add the number of duplicates in a new list.
My code is:
mylist = [a,a,a,b,c,c,a,d,e,e,e]
result = list(dict.fromkeys(mylist))
==> [a,b,c,d,e]
It's not the expected result.