I’m asking the user to input a keyword and then remove any duplicate characters.
Example:
Input: balloon
Output: balon
I’ve tried this solution: List of all unique characters in a string? but it marks it as a syntax error.
Any ideas?
Advertisement
Answer
For your answer, order is important. Here is a one line solution:
word = raw_input() reduced_word = ''.join( [char for index, char in enumerate(word) if char not in word[0:index]])