<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def nodes(self, frequency=None):
 """ Returns all nodes of the specified frequency that are related to the given Session Parameters frequency : str | None The frequency of the nodes to return Returns ------- nodes : iterable[TreeNode] All nodes related to the Session for the specified frequency """

        if frequency is None:
            []
        elif frequency == 'per_session':
            return [self]
        elif frequency in ('per_visit', 'per_subject'):
            return [self.parent]
        elif frequency == 'per_study':
            return [self.parent.parent]