Python Code to find the number of hapax legomena in a Text or Words_List In corpus linguistics, a hapax legomenon is a word that occurs only once within a context, either in the written record of an entire language, in the works of an author, or in a single text. The term is sometimes incorrectly used to describe a word that occurs in just one of an author's works, but more than once in that particular work. Hapax legomenon is a transliteration of Greek ἅπαξ λεγόμενον, meaning "(something) being said (only) once"

Hapax_legomenon
enter link description here
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)