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
Post a Comment