File tree 1 file changed +10
-17
lines changed
1 file changed +10
-17
lines changed Original file line number Diff line number Diff line change 1
1
VOWELS = list ('aeiou' )
2
- text = """Python is an easy to learn, powerful programming language."
2
+ text = """Python is an easy to learn, powerful programming language."
3
3
"It has efficient high-level data structures and a simple "
4
4
"but effective approach to object-oriented programming. "
5
5
"Python’s elegant syntax and dynamic typing, together with "
6
6
"its interpreted nature, make it an ideal language for "
7
7
"scripting and rapid application development in many areas "
8
8
"on most platforms."""
9
9
10
+
11
+ def count_vowels (word ):
12
+ return len ([v for v in word if v in VOWELS ])
13
+
14
+
10
15
def get_word_max_vowels (text ):
11
16
"""Get the case insensitive word in text that has most vowels.
12
17
Return a tuple of the matching word and the vowel count, e.g.
13
18
('object-oriented', 6)"""
14
19
# print(type(text))
15
- words = []
16
- for line in text .splitlines ():
17
- line = [word .lower () for word in line .split (" " ) if len (word ) > 0 ]
18
- words .append (line )
19
- listofwords = []
20
- for list in words :
21
- listofwords += list
22
- result = []
23
- for word in listofwords :
24
- point = 0
25
- for ch in word :
26
- if ch in VOWELS :
27
- point += 1
28
- result .append ((word ,point ))
29
- result .sort (key = lambda x :x [1 ])
30
- return result [- 1 ]
20
+ words = text .lower ().split (" " )
21
+ words = [(word , count_vowels (word )) for word in words ]
22
+ return max (words ,key = lambda x : x [1 ])
23
+
31
24
32
25
print (get_word_max_vowels (text ))
You can’t perform that action at this time.
0 commit comments