-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimperative.py
More file actions
38 lines (24 loc) · 984 Bytes
/
imperative.py
File metadata and controls
38 lines (24 loc) · 984 Bytes
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
33
34
35
36
37
38
original_text = "Everything should be built top-down, except the first time."
unwanted_characters = [',', '.']
string_without_punctuation = ''
for character in original_text:
if character not in unwanted_characters:
string_without_punctuation += character
string_lower_case = string_without_punctuation.lower()
word_list = string_lower_case.split()
word_list_length = len(word_list)
print("Total words:", word_list_length)
word_to_search = 'except'
word_match_counter = 0
for word in word_list:
if word == word_to_search:
word_match_counter += 1
print('Number of occurances of word match:', word_match_counter)
match_character = 'e'
words_beginning_with_character = []
for word in word_list:
if word[0] == match_character:
words_beginning_with_character.append(word)
print("Words beginning with character:", words_beginning_with_character)
print("Number of words beginning with character:",
len(words_beginning_with_character))