1
+ text = """
2
+ The Zen of Python, by Tim Peters
3
+
4
+ Beautiful is better than ugly.
5
+ Explicit is better than implicit.
6
+ Simple is better than complex.
7
+ Complex is better than complicated.
8
+ Flat is better than nested.
9
+ Sparse is better than dense.
10
+ Readability counts.
11
+ Special cases aren't special enough to break the rules.
12
+ Although practicality beats purity.
13
+ Errors should never pass silently.
14
+ Unless explicitly silenced.
15
+ In the face of ambiguity, refuse the temptation to guess.
16
+ There should be one-- and preferably only one --obvious way to do it.
17
+ Although that way may not be obvious at first unless you're Dutch.
18
+ Now is better than never.
19
+ Although never is often better than *right* now.
20
+ If the implementation is hard to explain, it's a bad idea.
21
+ If the implementation is easy to explain, it may be a good idea.
22
+ Namespaces are one honking great idea -- let's do more of those!
23
+ """
24
+ vowels = 'aeiou'
25
+
26
+
27
+ def strip_vowels (text : str ) -> (str , int ):
28
+ """Replace all vowels in the input text string by a star
29
+ character (*).
30
+ Return a tuple of (replaced_text, number_of_vowels_found)
31
+
32
+ So if this function is called like:
33
+ strip_vowels('hello world')
34
+
35
+ ... it would return:
36
+ ('h*ll* w*rld', 3)
37
+
38
+ The str/int types in the function defintion above are part
39
+ of Python's new type hinting:
40
+ https://docs.python.org/3/library/typing.html"""
41
+ listkun = list (text )
42
+ count = 0
43
+ for x in listkun :
44
+ if x in vowels or x in "AEIOU" :
45
+ count += 1
46
+
47
+ text = text .replace ('a' , '*' )
48
+ text = text .replace ('e' , '*' )
49
+ text = text .replace ('i' , '*' )
50
+ text = text .replace ('o' , '*' )
51
+ text = text .replace ('u' , '*' )
52
+ text = text .replace ('A' , '*' )
53
+ text = text .replace ('E' , '*' )
54
+ text = text .replace ('I' , '*' )
55
+ text = text .replace ('O' , '*' )
56
+ text = text .replace ('U' , '*' )
57
+
58
+ return (text , count )
59
+
60
+ # print(strip_vowels(text))
61
+ print (strip_vowels (text ))
0 commit comments