<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def bell_set(self, collection, ordinal=False):
 """ Calculates the Bell set """

        if len(collection) == 1:
            yield [ collection ]
            return

        first = collection[0]
        for smaller in self.bell_set(collection[1:]):
            for n, subset in enumerate(smaller):
                if not ordinal or (ordinal and is_sorted(smaller[:n] + [[ first ] + subset] + smaller[n+1:], self._nan)):
                    yield smaller[:n] + [[ first ] + subset] + smaller[n+1:]

            if not ordinal or (ordinal and is_sorted([ [ first ] ] + smaller, self._nan)):
                yield [ [ first ] ] + smaller