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

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

u/cyber_r0nin Apr 27 '22

You are a scholar! Knew a 2nd pair of eyes would catch my fuck up.