-
I take in a string
aabullc -
newstring should be assigned
aallafter the loop sinceaandlare duplicates -
strings with more then 1 dupe like
aaabullcshould returnaaalldef rearrangeLetters(S): print(len(S)) start = 0 newstring = "" for i in range(start+1, len(S)): if(S[start] == S[i]): newstring+=S[i] print(newstring) start +=1
issue:
print(newstring) is never running
>Solution :
Try this:
def rearrangeLetters(S):
s = [S[i] for i in range(len(S))]
newstring = ""
for t in s:
if s.count(t) > 1:
newstring += t
return newstring
call function:
output = rearrangeLetters("aabullc")
print(output)
output:
aall