Skip to content
Advertisement

How to remove characters that appear more than once from a string?

So, I had a similar exercise on my IT classes: ‘Print a string without characters appearing more than once (if they appear more than once, remove them)’. I thought that it was easy (and maybe it is), but I have completely no idea how to do that. I can do similar exercises (print all unique characters from a string / remove duplicates etc).

Example:

Input: ‘12345555555678’

Output: ‘1234678’

Advertisement

Answer

You could use collections.Counter().

JavaScript

Simple implementation of Counter

JavaScript
Advertisement