How can I pass in an optional argument to user-defined function whereas when the argument is called, it filters the original data and when it’s omitted, original data is not filtered
import spacy
from collections import Counter
nlp = spacy.load('en')
txt=“””Though the disease was eradicated decades ago, national security experts fear that stocks of the virus in labs could be released as a bioweapon.”””
doc = nlp(txt)
def common_pos(doc, n, pos):
words = [token.lemma_ for token in doc if token.is_stop != True and token.is_punct != True and token.pos_ == pos]
word_freq = Counter(words)
common_words =word_freq.most_common(n)
print(common_words)
Here pos is the optional argument. The desired behaviour is that if I don’t pass in pos, it shows the most common words, whereas if I pass ‘VERB’ as pos, it shows the most common verb.
How could I make this an optional argument? Thanks