r/CodingHelp • u/cyber_r0nin • 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
u/NoGarbage5153 Apr 27 '22
fuckery = 'how many fucks do i give?'words = word_tokenize(fuckery)print(words)fucks = [word for word in words if 'fuck' in word]print(fucks)print(len(fucks))
1
3
3
u/serg06 Apr 26 '22 edited Apr 26 '22
Why would you expect it to print 1?