r/CodingHelp • • Apr 26 '22

[Python] Can't debug this right... NSFW

Supposed to be 1 but keeps coming up 0.

from nltk.tokenize import sent_tokenize, word_tokenize import re

fuckery = 'How many fucks do I give?'

word_list = (word_tokenize(fuckery)) word_list_copy = [word for word in word_list]

print(word_tokenize(fuckery))

has_fucked = [word for word in word_list if 'fuck' in word] how_many_fucks = word_list.count('fuck') print(has_fucked) print('How many fucks?: ' , how_many_fucks, ' times')

Also, is there a better way to optimize this?

2 Upvotes

7 comments sorted by

View all comments

3

u/serg06 Apr 26 '22 edited Apr 26 '22

Why would you expect it to print 1?

2

u/cyber_r0nin Apr 26 '22

I've corrected the import statement mistake. I had to type it manually...

Also, there is at least 1 fucks in there...

1

u/Long_Investment7667 Apr 27 '22

Can you please state what your program is supposed to do or do you want us to guess?

1

u/cyber_r0nin Apr 27 '22

You at least give a fuck so I'll explain. It should parse the sentence into separate words. Then it should find the word in question, count the availability of said word, and lastly print out its existence.