a = aaabbbbccccdefklmopqwwxxxxxyyyyy My question would be, what kind of code should I write in Python in order to: b =abcdefklmopqwxy
so all characters should be appear only once. I am totally newbiew, any answer would be approriated.
a = aaabbbbccccdefklmopqwwxxxxxyyyyy My question would be, what kind of code should I write in Python in order to: b =abcdefklmopqwxy
so all characters should be appear only once. I am totally newbiew, any answer would be approriated.
Try this:
print("".join(sorted(set("aaabbbbccccdefklmopqwwxxxxxyyyyy"))))
Output:
abcdefklmopqwxy
As suggest in the comments by @Matthias you can get the job done with itertools
, but this time the order is based on the original string.
import itertools
print(''.join(g[0] for g in itertools.groupby("aaabbbbccccdefklmopqwwxxxxxyyyyy")))
Output:
abcdefklmopqwxy