<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lemmatize(self, text, best_guess=True, return_frequencies=False):

 		"""Lemmatize all tokens in a string or a list. A string is first tokenized using punkt.
 		Throw a type error if the input is neither a string nor a list.
 		"""

		if isinstance(text, str):
			tokens = wordpunct_tokenize(text)
		elif isinstance(text, list):
			tokens= text
		else:
			raise TypeError("lemmatize only works with strings or lists of string tokens.")

		return [self._lemmatize_token(token, best_guess, return_frequencies) for token in tokens]