Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TaikiShiba opened this issue Sep 26, 2023 · 0 comments
Open

Comments

@TaikiShiba
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant