<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ls(root=".", abspaths=False, recursive=False):
 """ Return a list of files in directory. Directory listings are sorted alphabetically. If the named directory is a file, return it's path. Examples: ["a", "b", "c"] ["foo/a"] ["/home/test/foo/a", "/home/test/foo/b", "/home/test/foo/c"] ["a", "b", "b/d", "b/d/e", "c"] Arguments: root (str):
 Path to directory. Can be relative or absolute. abspaths (bool, optional):
 Return absolute paths if true. recursive (bool, optional):
 Recursively list subdirectories if true. Returns: list of str: A list of paths. Raises: OSError: If root directory does not exist. """

    def _expand_subdirs(file):
        if isdir(path(root, file)):
            return [file] + [path(file, x) for x in
                             ls(path(root, file), recursive=True)]
        else:
            return [file]

    if isfile(root):
        # If argument is a file, return path.
        return [abspath(root)] if abspaths else [basename(root)]
    elif abspaths:
        # Get relative names.
        relpaths = ls(root, recursive=recursive, abspaths=False)
        # Prepend the absolute path to each relative name.
        base = abspath(root)
        return [path(base, relpath) for relpath in relpaths]
    elif recursive:
        # Recursively expand subdirectories.
        paths = ls(root, abspaths=abspaths, recursive=False)
        return labtypes.flatten([_expand_subdirs(file) for file in paths])
    else:
        # List directory contents.
        return list(sorted(os.listdir(root)))