<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_sorted_iterator(self, iterator):
 """ Get the iterator over the sorted items. This function decides whether the items can be sorted in memory or on disk. :return: """

        lines = list(next(iterator))
        if len(lines) < self.max_lines:
            return iter(sorted(lines, key=self.key))

        import tempfile
        tmp_dir = tempfile.mkdtemp()
        fnames = self._split(chain([lines], iterator), tmp_dir)
        return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key)