Skip to content

Commit a36a5b4

Browse files
authored
Create unit7_ex7.2.5.py
1 parent af66e41 commit a36a5b4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

unit7_ex7.2.5.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# exercise 7.2.5 from unit 7
2+
'''
3+
Write a function called sequence_del defined as follows:
4+
5+
def sequence_del(my_str):
6+
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.
7+
8+
Running examples of the sequence_del function
9+
>>> sequence_del("ppyyyyythhhhhooonnnnn")
10+
python
11+
>>> sequence_del("SSSSsssshhhh")
12+
'ssh'
13+
>>> sequence_del("Heeyyy yyouuuu!!!")
14+
'Hey you!'
15+
'''
16+
17+
def sequence_del(my_str):
18+
result = ""
19+
prev_char = ""
20+
for char in my_str:
21+
if char != prev_char:
22+
result += char
23+
prev_char = char
24+
return result
25+
26+
def main():
27+
print(sequence_del("ppyyyyythhhhhooonnnnn"))
28+
print(sequence_del("SSSSsssshhhh"))
29+
print(sequence_del("Heeyyy yyouuuu!!!"))
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)