python - Removing only alpha duplicates -


in python, remove duplicate letters string, not numbers or spaces. came with:

result = [] seen = set() char in string:     if char not in seen:         seen.add(char)         result.append(char) return "".join(result) 

but makes:

>>> delete_duplicate_letters("13 men wounded in explosion yesterday around 3:00pm.") 13 menwroudiaxplsyt:0. 

when want:

>>> delete_duplicate_letters("13 men wounded in explosion yesterday around 3:00pm.") 13 men wr oud xpls yt 3:00. 

i've tried use letter instead of char, isalpha() function , if int statements etc couldn't work.

try this:

result = "" char in string:     if not (char.isalpha() , char in result):         result += char 

Comments