Python Code to find the number of hapax legomena in a Text or Words_List
You can use nltk's freq dist, there is a built in method there for that.
from nltk.probability import FreqDist
from nltk import Text

self.text = Text(self.tokens)
self.fdist = FreqDist(self.text)    
hapaxes = fdist1.hapaxes()

if by any chance you cannot use the library, feel free to manually calculate it:
text = 'your text ... '
local_hapax = list(set(text.split(' ')))
weighted_local_hapax = local_hapax/len(text)