Python Removing Duplicates in a String Using in and not in -


i'm trying use in , not in operators accumulator pattern remove duplicate letters string , return new string while maintaining order.

withdups = "the quick brown fox jumped on lazy dog"  def removedups(s):     alphabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"     swithoutdups = ""     eachchar in withdups:         if eachchar in alphabet:             swithoutdups = eachchar + swithoutdups         return swithoutdups  print(removedups(withdups)) 

my current code returns first letter of string. i'm new python , coding in general, please excuse if i'm overlooking simple, current code not right direction, or if i'm posting shouldn't be.

withdups = "the quick brown fox jumped on lazy dog" withoutdups = ""  letter in withdups:     if letter not in withoutdups:         withoutdups += letter  print withoutdups 

have in mind whitespaces considered character too.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -