-2

The task i recieved :

Examples of running the sequence_del function :

>>> sequence_del("ppyyyyythhhhhooonnnnn") 
'python'
>>> sequence_del("SSSSsssshhhh") 
'Ssh'
>>> sequence_del("Heeyyy   yyouuuu!!!") 
'Hey you!'

The code I wrote :

def sequence_del(my_str):  # the function deletes duplicated characters.
    l = []
    for ch in my_str:
        if ch not in l:
            l.append(ch)
    print("".join(l))

For some reason i can't think of a way to cover the 3rd example in the task . Would love some help with it !

Liran Sarel
  • 39
  • 1
  • 5

1 Answers1

1

try this

def sequence_del(my_str):  # the function deletes duplicated characters.
    l = []
    last=''
    for ch in my_str:
        if last!=ch:
            l.append(ch)
            last = ch

    print("".join(l))
nishant
  • 2,526
  • 1
  • 13
  • 19