Note: Please make sure this is not duplicate, i am trying to find one liner way.
I am trying to turn string filled with ascii letters to string filled with occurrence of ascii letters.
For example:
string1 = 'abc'
.
To turn this into string filled with occurrence of ascii letters, i would simply use one line command:
string2 = [string1.count(l) for l in string1]
And this would output:
[1, 1, 1]
But if i had multiple repeated characters in string1, it would look different.
For example: string1 = 'aaabbbccc'
And transforming it:
string2 = [string1.count(l) for l in string1]
And output would be:
[3, 3, 3, 3, 3, 3, 3, 3, 3]
So as you see, character occurrences are repeated, and i don't know how can i make a generator that prints single occurrence of single letter only once.
So for example:
Instead of:
[3, 3, 3, 3, 3, 3, 3, 3, 3]
Is there a way to output this with single line generator?
[3, 3, 3]