You can do this quickly with the Counter class.
>>> s='yo i went jogging then yo i went joggin tuesday wednesday'
>>> from collections import Counter
>>> Counter(s.split())
Counter({'yo': 2, 'i': 2, 'went': 2, 'joggin': 1, 'then': 1, 'tuesday': 1, 'wednesday': 1, 'jogging': 1})
Then simply iterate through the returned dictionary looking for words with a count of 1
>>> c=Counter(s.split())
>>> for w in c:
... if c[w] == 1:
... print w
...
joggin
then
tuesday
wednesday
jogging
>>>
You'll note that you actually have five hapaxes in that string: joggin, then, tuesday, wednesday, and jogging.
You may need additional logic to decide if "Jogging" and "jogging" are different words. You also need to decide if punctuation counts (and remove if it it shouldn't). That is all dependent on the fine requirements of your problem statement.
Regarding your original code, I'm not sure what you were trying to accomplish with this loop:
for y in l:
w += y
It simply concatenates all the words into a single string with no spaces. Thus, if l is ['the','cat','sat','on','the','mat']
, w
will be 'thecatsatonthemat'
which may cause problems in your match. If the original string contained "I may be that maybe you are right", the words "may be" would concatentate to "maybe" and find
would find them.