-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit7_ex7.2.5.py
32 lines (27 loc) · 894 Bytes
/
unit7_ex7.2.5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# exercise 7.2.5 from unit 7
'''
Write a function called sequence_del defined as follows:
def sequence_del(my_str):
The function accepts a string and deletes the letters appearing in sequence. That is, the function returns a string in which only one character appears from each sequence of identical characters in the input string.
Running examples of the sequence_del function
>>> sequence_del("ppyyyyythhhhhooonnnnn")
python
>>> sequence_del("SSSSsssshhhh")
'ssh'
>>> sequence_del("Heeyyy yyouuuu!!!")
'Hey you!'
'''
def sequence_del(my_str):
result = ""
prev_char = ""
for char in my_str:
if char != prev_char:
result += char
prev_char = char
return result
def main():
print(sequence_del("ppyyyyythhhhhooonnnnn"))
print(sequence_del("SSSSsssshhhh"))
print(sequence_del("Heeyyy yyouuuu!!!"))
if __name__ == "__main__":
main()