import os
def files_and_folders(dir_path='.'):
    files = []
    folders = []
    for filename in sorted(os.listdir(dir_path)):
        if os.path.isdir(os.path.join(dir_path, filename)):
            folders.append(filename)
        else:
            files.append(filename)
    return tuple(files), tuple(folders)

import os

# improvement liberally borrowed from:
# https://forum.omz-software.com/topic/2784/feature-request-pythonista-built-in-file-picker


def files_and_folders(dir_path='.'):
    '''Return a dict containing a sorted tuple of files and a sorted
    tuple of folders'''
    f_and_f = os.listdir(dir_path)
    folders = [f for f in f_and_f if os.path.isdir(os.path.abspath(f))]
    files = set(f_and_f) - set(folders)
    return {'files': tuple(sorted(files)), 'folders': tuple(sorted(folders))}


def old_files_and_folders(dir_path='.'):
    files = []
    folders = []
    for filename in sorted(os.listdir(dir_path)):
        if os.path.isdir(os.path.join(dir_path, filename)):
            folders.append(filename)
        else:
            files.append(filename)
    return tuple(files), tuple(folders)

print(files_and_folders())

Cut number of lines in half
Cut number of lines in half

@The-Penultimate-Defenestrator use of sets is a nice optimization!

# improvement liberally borrowed from:
# https://forum.omz-software.com/topic/2784/feature-request-pythonista-built-in-file-picker
  import os
+ 
+ # improvement liberally borrowed from:
+ # https://forum.omz-software.com/topic/2784/feature-request-pythonista-built-in-file-picker
+ 
+ 
  def files_and_folders(dir_path='.'):
+     '''Return a dict containing a sorted tuple of files and a sorted
+     tuple of folders'''
+     f_and_f = os.listdir(dir_path)
+     folders = [f for f in f_and_f if os.path.isdir(os.path.abspath(f))]
+     files = set(f_and_f) - set(folders)
+     return {'files': tuple(sorted(files)), 'folders': tuple(sorted(folders))}
+ 
+ 
+ def old_files_and_folders(dir_path='.'):
      files = []
      folders = []
      for filename in sorted(os.listdir(dir_path)):
          if os.path.isdir(os.path.join(dir_path, filename)):
              folders.append(filename)
          else:
              files.append(filename)
      return tuple(files), tuple(folders)
  
+ print(files_and_folders())
+ 
Cut number of lines in half
## Code Before:
import os
def files_and_folders(dir_path='.'):
    files = []
    folders = []
    for filename in sorted(os.listdir(dir_path)):
        if os.path.isdir(os.path.join(dir_path, filename)):
            folders.append(filename)
        else:
            files.append(filename)
    return tuple(files), tuple(folders)

## Instruction:
Cut number of lines in half
## Code After:
import os

# improvement liberally borrowed from:
# https://forum.omz-software.com/topic/2784/feature-request-pythonista-built-in-file-picker


def files_and_folders(dir_path='.'):
    '''Return a dict containing a sorted tuple of files and a sorted
    tuple of folders'''
    f_and_f = os.listdir(dir_path)
    folders = [f for f in f_and_f if os.path.isdir(os.path.abspath(f))]
    files = set(f_and_f) - set(folders)
    return {'files': tuple(sorted(files)), 'folders': tuple(sorted(folders))}


def old_files_and_folders(dir_path='.'):
    files = []
    folders = []
    for filename in sorted(os.listdir(dir_path)):
        if os.path.isdir(os.path.join(dir_path, filename)):
            folders.append(filename)
        else:
            files.append(filename)
    return tuple(files), tuple(folders)

print(files_and_folders())
