Skip to content

Chapter2 Listing 2.3 returned [' ', ' ', ' ', ' ', ' ', ' ', ' '] #1

@TaikiShiba

Description

@TaikiShiba

Hi. I tried the code in Chapter2 Listing 2.3, which is the following:

text = 'Define which data represents "ham" class and which data represents "spam" class for the machine-learning algorithm.'
text = "i. e."
delimiters = ['"', "."]
words = []
current_word = ""
for char in text:
if char==" ":
if not current_word=="":
words.append(current_word)
current_word = ""
elif char in delimiters:
if current_word=="":
words.append(char)
else:
words.append(current_word)
words.append(char)
current_word = ""
else:
current_word += char

print(words)

But it returned [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']. Would you happen to know why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions